Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions integrations/slack/gitbook-manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ secrets:
CLIENT_SECRET: ${{ env.SLACK_CLIENT_SECRET }}
SIGNING_SECRET: ${{ env.SLACK_SIGNING_SECRET }}
OPENAI_API_KEY: ${{ env.SLACK_OPENAI_API_KEY }}
REFLAG_SECRET_KEY: ${{ env.REFLAG_SECRET_KEY }}
envs:
dev-steeve:
organization: idE5kUnGGjoPGcbu3FZJ
Expand All @@ -87,22 +88,26 @@ envs:
CLIENT_SECRET: ${{ "op://gitbook-integrations/slackDevSteeve/CLIENT_SECRET" }}
SIGNING_SECRET: ${{ "op://gitbook-integrations/slackDevSteeve/SIGNING_SECRET" }}
OPENAI_API_KEY: ${{ "op://gitbook-integrations/slackDevSteeve/OPENAI_API_KEY" }}
REFLAG_SECRET_KEY: ${{ "op://gitbook-integrations/reflagDev/REFLAG_SECRET_KEY" }}
test:
secrets:
CLIENT_ID: ${{ "op://gitbook-integrations/slackStaging/CLIENT_ID" }}
CLIENT_SECRET: ${{ "op://gitbook-integrations/slackStaging/CLIENT_SECRET" }}
SIGNING_SECRET: ${{ "op://gitbook-integrations/slackStaging/SIGNING_SECRET" }}
OPENAI_API_KEY: ${{ "op://gitbook-integrations/slackStaging/OPENAI_API_KEY" }}
REFLAG_SECRET_KEY: ${{ "op://gitbook-integrations/reflagStaging/REFLAG_SECRET_KEY" }}
staging:
secrets:
CLIENT_ID: ${{ "op://gitbook-integrations/slackStaging/CLIENT_ID" }}
CLIENT_SECRET: ${{ "op://gitbook-integrations/slackStaging/CLIENT_SECRET" }}
SIGNING_SECRET: ${{ "op://gitbook-integrations/slackStaging/SIGNING_SECRET" }}
OPENAI_API_KEY: ${{ "op://gitbook-integrations/slackStaging/OPENAI_API_KEY" }}
REFLAG_SECRET_KEY: ${{ "op://gitbook-integrations/reflagStaging/REFLAG_SECRET_KEY" }}
prod:
secrets:
CLIENT_ID: ${{ "op://gitbook-integrations/slackProd/CLIENT_ID" }}
CLIENT_SECRET: ${{ "op://gitbook-integrations/slackProd/CLIENT_SECRET" }}
SIGNING_SECRET: ${{ "op://gitbook-integrations/slackProd/SIGNING_SECRET" }}
OPENAI_API_KEY: ${{ "op://gitbook-integrations/slackProd/OPENAI_API_KEY" }}
REFLAG_SECRET_KEY: ${{ "op://gitbook-integrations/reflagProd/REFLAG_SECRET_KEY" }}
target: space
38 changes: 26 additions & 12 deletions integrations/slack/src/actions/ingestConversation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { ConversationInput, ConversationPart, IntegrationInstallation } from '@gitbook/api';
import { SlackInstallationConfiguration, SlackRuntimeContext } from '../configuration';
import { getSlackThread, slackAPI, SlackConversationThread } from '../slack';
import { getInstallationApiClient, getIntegrationInstallationForTeam } from '../utils';
import {
getInstallationApiClient,
getIntegrationInstallationForTeam,
isDocsAgentsConversationsEnabled,
} from '../utils';
import { IngestSlackConversationActionParams } from './types';
import { Logger } from '@gitbook/runtime';

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

const isDocsAgentsEnabled = await isDocsAgentsConversationsEnabled({
organizationId: installation.target.organization,
context,
});
const appOrgURL = installation.urls.app.replace('/integrations/slack', '');

await Promise.all([
slackAPI(
context,
Expand All @@ -29,24 +39,28 @@ export async function ingestSlackConversation(params: IngestSlackConversationAct
path: 'chat.postMessage',
payload: {
channel: channelId,
text: `🚀 Sharing this conversation with Docs Agent to improve your docs...`,
text: isDocsAgentsEnabled
? `🚀 Sharing this conversation with Docs Agent to improve your docs...`
: `✨ Docs Agent is currently in private alpha.\n\nRequest early access for your organization: ${appOrgURL}/agents`,
thread_ts: threadId,
},
},
{
accessToken,
},
),
handleIngestSlackConversationAction(
{
channelId,
threadId,
installation,
accessToken,
conversationToIngest,
},
context,
),
isDocsAgentsEnabled
? handleIngestSlackConversationAction(
{
channelId,
threadId,
installation,
accessToken,
conversationToIngest,
},
context,
)
: Promise.resolve(),
]);
}

Expand Down
33 changes: 33 additions & 0 deletions integrations/slack/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,36 @@ export function isAllowedToRespond(eventPayload: any) {

return !isFromBot && !isExternalChannel;
}

/**
* Check if Docs agents conversation is enabled for the organization.
*
* TODO: Remove when Docs agents reached general availability.
*/
export async function isDocsAgentsConversationsEnabled(params: {
organizationId: string;
context: SlackRuntimeContext;
}): Promise<boolean> {
const { organizationId, context } = params;
try {
const response = await fetch(
`https://front.reflag.com/features/enabled?context.company.id=${organizationId}&key=DOCS_AGENTS_CONVERSATIONS`,
{
method: 'GET',
headers: {
Authorization: `Bearer ${context.environment.secrets.REFLAG_SECRET_KEY}`,
'Content-Type': 'application/json',
},
},
);

const json = (await response.json()) as {
features: { DOCS_AGENTS_CONVERSATIONS: { isEnabled: boolean } };
};
const flag = json.features.DOCS_AGENTS_CONVERSATIONS;

return flag.isEnabled;
} catch (e) {
return false;
}
}