Skip to content

Commit 3fbc3ae

Browse files
authored
Feature flag conversations ingestion in Slack integration (#1043)
* Feature flag conversation ingestion * Pull reflag secret from op * Use app URL based on intengration installation instead of hard coded one
1 parent f9a4bbf commit 3fbc3ae

File tree

3 files changed

+64
-12
lines changed

3 files changed

+64
-12
lines changed

integrations/slack/gitbook-manifest.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ secrets:
7979
CLIENT_SECRET: ${{ env.SLACK_CLIENT_SECRET }}
8080
SIGNING_SECRET: ${{ env.SLACK_SIGNING_SECRET }}
8181
OPENAI_API_KEY: ${{ env.SLACK_OPENAI_API_KEY }}
82+
REFLAG_SECRET_KEY: ${{ env.REFLAG_SECRET_KEY }}
8283
envs:
8384
dev-steeve:
8485
organization: idE5kUnGGjoPGcbu3FZJ
@@ -87,22 +88,26 @@ envs:
8788
CLIENT_SECRET: ${{ "op://gitbook-integrations/slackDevSteeve/CLIENT_SECRET" }}
8889
SIGNING_SECRET: ${{ "op://gitbook-integrations/slackDevSteeve/SIGNING_SECRET" }}
8990
OPENAI_API_KEY: ${{ "op://gitbook-integrations/slackDevSteeve/OPENAI_API_KEY" }}
91+
REFLAG_SECRET_KEY: ${{ "op://gitbook-integrations/reflagDev/REFLAG_SECRET_KEY" }}
9092
test:
9193
secrets:
9294
CLIENT_ID: ${{ "op://gitbook-integrations/slackStaging/CLIENT_ID" }}
9395
CLIENT_SECRET: ${{ "op://gitbook-integrations/slackStaging/CLIENT_SECRET" }}
9496
SIGNING_SECRET: ${{ "op://gitbook-integrations/slackStaging/SIGNING_SECRET" }}
9597
OPENAI_API_KEY: ${{ "op://gitbook-integrations/slackStaging/OPENAI_API_KEY" }}
98+
REFLAG_SECRET_KEY: ${{ "op://gitbook-integrations/reflagStaging/REFLAG_SECRET_KEY" }}
9699
staging:
97100
secrets:
98101
CLIENT_ID: ${{ "op://gitbook-integrations/slackStaging/CLIENT_ID" }}
99102
CLIENT_SECRET: ${{ "op://gitbook-integrations/slackStaging/CLIENT_SECRET" }}
100103
SIGNING_SECRET: ${{ "op://gitbook-integrations/slackStaging/SIGNING_SECRET" }}
101104
OPENAI_API_KEY: ${{ "op://gitbook-integrations/slackStaging/OPENAI_API_KEY" }}
105+
REFLAG_SECRET_KEY: ${{ "op://gitbook-integrations/reflagStaging/REFLAG_SECRET_KEY" }}
102106
prod:
103107
secrets:
104108
CLIENT_ID: ${{ "op://gitbook-integrations/slackProd/CLIENT_ID" }}
105109
CLIENT_SECRET: ${{ "op://gitbook-integrations/slackProd/CLIENT_SECRET" }}
106110
SIGNING_SECRET: ${{ "op://gitbook-integrations/slackProd/SIGNING_SECRET" }}
107111
OPENAI_API_KEY: ${{ "op://gitbook-integrations/slackProd/OPENAI_API_KEY" }}
112+
REFLAG_SECRET_KEY: ${{ "op://gitbook-integrations/reflagProd/REFLAG_SECRET_KEY" }}
108113
target: space

integrations/slack/src/actions/ingestConversation.ts

Lines changed: 26 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,12 @@ 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+
const appOrgURL = installation.urls.app.replace('/integrations/slack', '');
33+
2434
await Promise.all([
2535
slackAPI(
2636
context,
@@ -29,24 +39,28 @@ export async function ingestSlackConversation(params: IngestSlackConversationAct
2939
path: 'chat.postMessage',
3040
payload: {
3141
channel: channelId,
32-
text: `🚀 Sharing this conversation with Docs Agent to improve your docs...`,
42+
text: isDocsAgentsEnabled
43+
? `🚀 Sharing this conversation with Docs Agent to improve your docs...`
44+
: `✨ Docs Agent is currently in private alpha.\n\nRequest early access for your organization: ${appOrgURL}/agents`,
3345
thread_ts: threadId,
3446
},
3547
},
3648
{
3749
accessToken,
3850
},
3951
),
40-
handleIngestSlackConversationAction(
41-
{
42-
channelId,
43-
threadId,
44-
installation,
45-
accessToken,
46-
conversationToIngest,
47-
},
48-
context,
49-
),
52+
isDocsAgentsEnabled
53+
? handleIngestSlackConversationAction(
54+
{
55+
channelId,
56+
threadId,
57+
installation,
58+
accessToken,
59+
conversationToIngest,
60+
},
61+
context,
62+
)
63+
: Promise.resolve(),
5064
]);
5165
}
5266

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=DOCS_AGENTS_CONVERSATIONS`,
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)