Skip to content

Commit 5213862

Browse files
committed
Feature flag conversation ingestion
1 parent 76227dd commit 5213862

File tree

3 files changed

+59
-12
lines changed

3 files changed

+59
-12
lines changed

integrations/slack/gitbook-manifest.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,5 @@ secrets:
7878
CLIENT_ID: ${{ env.SLACK_CLIENT_ID }}
7979
CLIENT_SECRET: ${{ env.SLACK_CLIENT_SECRET }}
8080
SIGNING_SECRET: ${{ env.SLACK_SIGNING_SECRET }}
81+
REFLAG_SECRET_KEY: ${{ env.REFLAG_SECRET_KEY }}
8182
target: space

integrations/slack/src/actions/ingestConversation.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { ConversationInput, ConversationPart, IntegrationInstallation } from '@gitbook/api';
22
import { SlackInstallationConfiguration, SlackRuntimeContext } from '../configuration';
33
import { getSlackThread, slackAPI, SlackConversationThread } from '../slack';
4-
import { getInstallationApiClient, getIntegrationInstallationForTeam } from '../utils';
4+
import {
5+
getInstallationApiClient,
6+
getIntegrationInstallationForTeam,
7+
isDocsAgentsConversationsEnabled,
8+
} from '../utils';
59
import { IngestSlackConversationActionParams } from './types';
610
import { Logger } from '@gitbook/runtime';
711

@@ -21,6 +25,11 @@ export async function ingestSlackConversation(params: IngestSlackConversationAct
2125
const accessToken = (installation.configuration as SlackInstallationConfiguration)
2226
.oauth_credentials?.access_token;
2327

28+
const isDocsAgentsEnabled = await isDocsAgentsConversationsEnabled({
29+
organizationId: installation.target.organization,
30+
context,
31+
});
32+
2433
await Promise.all([
2534
slackAPI(
2635
context,
@@ -29,24 +38,28 @@ export async function ingestSlackConversation(params: IngestSlackConversationAct
2938
path: 'chat.postMessage',
3039
payload: {
3140
channel: channelId,
32-
text: `🚀 Sharing this conversation with Docs Agent to improve your docs...`,
41+
text: isDocsAgentsEnabled
42+
? `🚀 Sharing this conversation with Docs Agent to improve your docs...`
43+
: `✨ Docs Agent is currently in private alpha.\n\nRequest early access for your organization: https://app.gitbook.com/o/${installation.target.organization}/agents`,
3344
thread_ts: threadId,
3445
},
3546
},
3647
{
3748
accessToken,
3849
},
3950
),
40-
handleIngestSlackConversationAction(
41-
{
42-
channelId,
43-
threadId,
44-
installation,
45-
accessToken,
46-
conversationToIngest,
47-
},
48-
context,
49-
),
51+
isDocsAgentsEnabled
52+
? handleIngestSlackConversationAction(
53+
{
54+
channelId,
55+
threadId,
56+
installation,
57+
accessToken,
58+
conversationToIngest,
59+
},
60+
context,
61+
)
62+
: Promise.resolve(),
5063
]);
5164
}
5265

integrations/slack/src/utils.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,36 @@ export function isAllowedToRespond(eventPayload: any) {
148148

149149
return !isFromBot && !isExternalChannel;
150150
}
151+
152+
/**
153+
* Check if Docs agents conversation is enabled for the organization.
154+
*
155+
* TODO: Remove when Docs agents reached general availability.
156+
*/
157+
export async function isDocsAgentsConversationsEnabled(params: {
158+
organizationId: string;
159+
context: SlackRuntimeContext;
160+
}): Promise<boolean> {
161+
const { organizationId, context } = params;
162+
try {
163+
const response = await fetch(
164+
`https://front.reflag.com/features/enabled?context.company.id=${organizationId}&key=GIT_SYNC_STATIC_IP`,
165+
{
166+
method: 'GET',
167+
headers: {
168+
Authorization: `Bearer ${context.environment.secrets.REFLAG_SECRET_KEY}`,
169+
'Content-Type': 'application/json',
170+
},
171+
},
172+
);
173+
174+
const json = (await response.json()) as {
175+
features: { DOCS_AGENTS_CONVERSATIONS: { isEnabled: boolean } };
176+
};
177+
const flag = json.features.DOCS_AGENTS_CONVERSATIONS;
178+
179+
return flag.isEnabled;
180+
} catch (e) {
181+
return false;
182+
}
183+
}

0 commit comments

Comments
 (0)