Skip to content

Commit

Permalink
Continue
Browse files Browse the repository at this point in the history
  • Loading branch information
SamyPesse committed Feb 3, 2025
1 parent 3bd6ac7 commit 69b0aed
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 274 deletions.
1 change: 1 addition & 0 deletions integrations/slack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@gitbook/tsconfig": "workspace:*"
},
"scripts": {
"typecheck": "tsc --noEmit",
"check": "gitbook check",
"publish-integrations": "gitbook publish .",
"publish-integrations-staging": "gitbook publish ."
Expand Down
6 changes: 1 addition & 5 deletions integrations/slack/slack-manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ display_information:
long_description: |
Experience the power of GitBook in your Slack workspace! 🚀
💾 *Save Threads in GitBook:*
Simply type ‘@gitbook save' in your Slack thread, and we'll swiftly capture it, turning your discussion into a living document. Now, anyone can easily search your team's captures and documents whenever they need them.
🔍 *Effortless Search:*
Start by using @gitbook [question]. Our advanced AI quickly scans your knowledge base, providing accurate and concise responses within seconds.
Start by using @gitbook [question]. Our advanced AI quickly scans your documentation, providing accurate and concise responses within seconds.
📢 *Stay Informed:*
Expand Down
26 changes: 16 additions & 10 deletions integrations/slack/src/actions/queryAskAI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
SlackRuntimeEnvironment,
SlackRuntimeContext,
} from '../configuration';
import { acknowledgeQuery } from '../middlewares';
import { slackAPI } from '../slack';
import { QueryDisplayBlock, ShareTools, decodeSlackEscapeChars, Spacer, SourcesBlock } from '../ui';
import { getInstallationApiClient, stripBotName, stripMarkdown } from '../utils';
Expand Down Expand Up @@ -174,16 +173,23 @@ export async function queryAskAI({
const parsedQuery = stripMarkdown(stripBotName(text, authorization?.user_id));

// async acknowledge the request to the end user early
acknowledgeQuery({
slackAPI(
context,
text: parsedQuery,
userId,
threadId,
channelId,
responseUrl,
accessToken,
messageType,
});
{
method: 'POST',
path: messageType === 'ephemeral' ? 'chat.postEphemeral' : 'chat.postMessage',
responseUrl,
payload: {
channel: channelId,
text: `_Asking: ${stripMarkdown(text)}_`,
...(userId ? { user: userId } : {}), // actually shouldn't be optional
...(threadId ? { thread_ts: threadId } : {}),
},
},
{
accessToken,
},
);

const result = await client.orgs.askInOrganization(installation.target.organization, {
query: parsedQuery,
Expand Down
5 changes: 3 additions & 2 deletions integrations/slack/src/handlers/actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type IQueryAskAI } from '../actions';
import { SlackRuntimeContext } from '../configuration';
import { getActionNameAndType, parseActionPayload } from '../utils';

/**
Expand All @@ -11,8 +12,8 @@ export function createSlackActionsHandler(
[type: string]: (event: object) => Promise<any>;
},
// TODO: type output
): any {
return async (request, context) => {
) {
return async (request: Request, context: SlackRuntimeContext) => {
const actionPayload = await parseActionPayload(request);

const { actions, container, channel, team, user } = actionPayload;
Expand Down
7 changes: 3 additions & 4 deletions integrations/slack/src/handlers/commands.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { FetchEventCallback } from '@gitbook/runtime';

import { SlackRuntimeContext } from '../configuration';

export interface SlashEvent {
Expand Down Expand Up @@ -33,10 +31,11 @@ export interface SlashEvent {

export function createSlackCommandsHandler(handlers: {
[type: string]: (slashEvent: SlashEvent, context: SlackRuntimeContext) => Promise<any>;
}): FetchEventCallback {
return async (request, context) => {
}) {
return async (request: Request, context: SlackRuntimeContext) => {
const requestText = await request.text();

// @ts-ignore
const slashEvent: SlashEvent = Object.fromEntries(
new URLSearchParams(requestText).entries(),
);
Expand Down
12 changes: 9 additions & 3 deletions integrations/slack/src/handlers/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@ import { isAllowedToRespond, parseEventPayload } from '../utils';
*/
export function createSlackEventsHandler(
handlers: {
[type: string]: (event: object, context: SlackRuntimeContext) => Promise<any>;
[type: string]: (event: any, context: SlackRuntimeContext) => Promise<any>;
},
fallback?: FetchEventCallback,
): FetchEventCallback {
return async (request, context) => {
) {
return async (request: Request, context: SlackRuntimeContext) => {
const eventPayload = await parseEventPayload(request);

// url_verification doesn't have an event object
const { type } = eventPayload.event ?? eventPayload;

if (!type) {
return new Response(`No event type found`, {
status: 404,
});
}

const handler = handlers[type];

// check if we are handling this event at this stage. if not, forward on to the fallback
Expand Down
2 changes: 1 addition & 1 deletion integrations/slack/src/handlers/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Logger } from '@gitbook/runtime';
import type { SlashEvent } from './commands';
import { queryAskAI } from '../actions';
import { SlackRuntimeContext } from '../configuration';
import { isAllowedToRespond, isSaveThreadMessage, stripBotName } from '../utils';
import { isAllowedToRespond, stripBotName } from '../utils';

const logger = Logger('slack:api');

Expand Down
1 change: 0 additions & 1 deletion integrations/slack/src/handlers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './search';
export * from './handlers';
export * from './actions';
export * from './commands';
Expand Down
140 changes: 0 additions & 140 deletions integrations/slack/src/handlers/search.ts

This file was deleted.

Loading

0 comments on commit 69b0aed

Please sign in to comment.