mirror of
https://github.com/eliasstepanik/core.git
synced 2026-01-11 17:18:28 +00:00
Fix: integration account handling and improve webhook event processing
This commit is contained in:
parent
b02c03390a
commit
34dfe6b823
@ -56,7 +56,7 @@ const { action, loader } = createHybridActionApiRoute(
|
||||
workspace?.id,
|
||||
);
|
||||
|
||||
if (!setupResult || !setupResult.accountId) {
|
||||
if (!setupResult.account || !setupResult.account.id) {
|
||||
return json(
|
||||
{ error: "Failed to setup integration with the provided API key" },
|
||||
{ status: 400 },
|
||||
@ -64,7 +64,7 @@ const { action, loader } = createHybridActionApiRoute(
|
||||
}
|
||||
|
||||
await tasks.trigger<typeof scheduler>("scheduler", {
|
||||
integrationAccountId: setupResult?.id,
|
||||
integrationAccountId: setupResult?.account?.id,
|
||||
});
|
||||
|
||||
return json({ success: true, setupResult });
|
||||
|
||||
@ -34,19 +34,20 @@ export async function action({ request, params }: ActionFunctionArgs) {
|
||||
eventBody: typeof eventBody === 'object' ? JSON.stringify(eventBody).substring(0, 200) : eventBody,
|
||||
});
|
||||
|
||||
const result = await webhookService.handleEvents(
|
||||
// Check if the event is a URL verification challenge (Slack)
|
||||
if (eventBody.type === "url_verification") {
|
||||
logger.log("Responding to Slack URL verification challenge");
|
||||
return json({ challenge: eventBody.challenge });
|
||||
}
|
||||
|
||||
await webhookService.handleEvents(
|
||||
sourceName,
|
||||
integrationAccountId,
|
||||
eventHeaders,
|
||||
eventBody
|
||||
);
|
||||
|
||||
// Handle URL verification challenge (returns different response)
|
||||
if (result.challenge) {
|
||||
return json({ challenge: result.challenge });
|
||||
}
|
||||
|
||||
return json({ status: result.status });
|
||||
return json({ status: 'acknowledged' }, { status: 200 });
|
||||
} catch (error) {
|
||||
logger.error('Webhook processing failed', { error, params });
|
||||
|
||||
@ -77,19 +78,20 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
|
||||
eventBody: JSON.stringify(eventBody).substring(0, 200),
|
||||
});
|
||||
|
||||
const result = await webhookService.handleEvents(
|
||||
// Check if the event is a URL verification challenge (Slack)
|
||||
if (eventBody.type === "url_verification") {
|
||||
logger.log("Responding to Slack URL verification challenge");
|
||||
return json({ challenge: eventBody.challenge });
|
||||
}
|
||||
|
||||
await webhookService.handleEvents(
|
||||
sourceName,
|
||||
integrationAccountId,
|
||||
eventHeaders,
|
||||
eventBody
|
||||
);
|
||||
|
||||
// Handle URL verification challenge (returns different response)
|
||||
if (result.challenge) {
|
||||
return json({ challenge: result.challenge });
|
||||
}
|
||||
|
||||
return json({ status: result.status });
|
||||
return json({ status: 'acknowledged' }, { status: 200 });
|
||||
} catch (error) {
|
||||
logger.error('Webhook GET processing failed', { error, params });
|
||||
|
||||
|
||||
@ -127,7 +127,7 @@ export async function callbackHandler(params: CallbackParams) {
|
||||
},
|
||||
);
|
||||
|
||||
const integrationAccount = await runIntegrationTrigger(
|
||||
const setupResult = await runIntegrationTrigger(
|
||||
integrationDefinition,
|
||||
{
|
||||
event: IntegrationEventType.SETUP,
|
||||
@ -144,7 +144,7 @@ export async function callbackHandler(params: CallbackParams) {
|
||||
);
|
||||
|
||||
await tasks.trigger<typeof scheduler>("scheduler", {
|
||||
integrationAccountId: integrationAccount?.id,
|
||||
integrationAccountId: setupResult?.account?.id,
|
||||
});
|
||||
|
||||
return new Response(null, {
|
||||
|
||||
@ -21,12 +21,6 @@ export class WebhookService {
|
||||
where: "WebhookService.handleEvents",
|
||||
});
|
||||
|
||||
// Check if the event is a URL verification challenge (Slack)
|
||||
if (eventBody.type === "url_verification") {
|
||||
logger.log("Responding to Slack URL verification challenge");
|
||||
return { challenge: eventBody.challenge, status: "verified" };
|
||||
}
|
||||
|
||||
let integrationAccount:
|
||||
| (IntegrationAccount & {
|
||||
integrationDefinition: IntegrationDefinitionV2;
|
||||
|
||||
@ -343,6 +343,7 @@ async function handleMessageResponse(
|
||||
responses.account = account;
|
||||
}
|
||||
|
||||
const unhandled: Message[] = [];
|
||||
// Warn for unknown message types
|
||||
for (const type of Object.keys(grouped)) {
|
||||
if (!["activity", "state", "identifier", "account"].includes(type)) {
|
||||
|
||||
@ -58,6 +58,6 @@
|
||||
"commander": "^12.0.0",
|
||||
"openai": "^4.0.0",
|
||||
"react-query": "^3.39.3",
|
||||
"@redplanethq/sdk": "0.1.1"
|
||||
"@redplanethq/sdk": "0.1.2"
|
||||
}
|
||||
}
|
||||
|
||||
10
integrations/slack/pnpm-lock.yaml
generated
10
integrations/slack/pnpm-lock.yaml
generated
@ -9,8 +9,8 @@ importers:
|
||||
.:
|
||||
dependencies:
|
||||
'@redplanethq/sdk':
|
||||
specifier: 0.1.1
|
||||
version: 0.1.1
|
||||
specifier: 0.1.2
|
||||
version: 0.1.2
|
||||
axios:
|
||||
specifier: ^1.7.9
|
||||
version: 1.9.0
|
||||
@ -465,8 +465,8 @@ packages:
|
||||
resolution: {integrity: sha512-ROFF39F6ZrnzSUEmQQZUar0Jt4xVoP9WnDRdWwF4NNcXs3xBTLgBUDoOwW141y1jP+S8nahIbdxbFC7IShw9Iw==}
|
||||
engines: {node: ^12.20.0 || ^14.18.0 || >=16.0.0}
|
||||
|
||||
'@redplanethq/sdk@0.1.1':
|
||||
resolution: {integrity: sha512-tfR1c9p7vNeCL5jsF9QlEZcRFLsihaHe/ZQWVKZYXzAZ6GugoIFBaayGfVvjNjyEnN3nlrl3usKBX+hhaKzg0g==}
|
||||
'@redplanethq/sdk@0.1.2':
|
||||
resolution: {integrity: sha512-Si+ae2OV0UNy7yvLECjJ1Y/6HHhRO0yU9svIFvBzMlaR/57SDP+KJZLyfWx/PJX+hOuWipyoYTLA9aYULt6z2w==}
|
||||
engines: {node: '>=18.0.0'}
|
||||
|
||||
'@rollup/rollup-android-arm-eabi@4.40.2':
|
||||
@ -2683,7 +2683,7 @@ snapshots:
|
||||
|
||||
'@pkgr/core@0.2.4': {}
|
||||
|
||||
'@redplanethq/sdk@0.1.1':
|
||||
'@redplanethq/sdk@0.1.2':
|
||||
dependencies:
|
||||
commander: 14.0.0
|
||||
|
||||
|
||||
@ -52,11 +52,10 @@ async function getConversationInfo(accessToken: string, channel: string) {
|
||||
|
||||
export const createActivityEvent = async (
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
eventBody: any,
|
||||
eventData: any,
|
||||
config: any,
|
||||
) => {
|
||||
const { eventData } = eventBody;
|
||||
if (eventData.event.type === 'message' && eventData.event.channel === 'D06UAK42494') {
|
||||
if (eventData.event.type === 'message' && eventData.event.channel === 'D08TQATE3F0') {
|
||||
const event = eventData.event;
|
||||
|
||||
if (!config) {
|
||||
@ -65,7 +64,7 @@ export const createActivityEvent = async (
|
||||
|
||||
const accessToken = config.access_token;
|
||||
|
||||
const text = `DM with SOL channel Content: '${event.text}'`;
|
||||
const text = `I DMed to you Content: '${event.text}'`;
|
||||
|
||||
const permalinkResponse = await axios.get(
|
||||
`https://slack.com/api/chat.getPermalink?channel=${event.channel}&message_ts=${event.ts}`,
|
||||
@ -81,7 +80,7 @@ export const createActivityEvent = async (
|
||||
taskId: null,
|
||||
};
|
||||
|
||||
return createActivityMessage(activity);
|
||||
return [createActivityMessage(activity)];
|
||||
}
|
||||
|
||||
if (eventData.event.type === 'reaction_added' && eventData.event.reaction === 'eyes') {
|
||||
@ -121,7 +120,7 @@ export const createActivityEvent = async (
|
||||
conversationContext = `channel ${conversationInfo.name}(${conversationInfo.id})`;
|
||||
}
|
||||
|
||||
const text = `Message to User from ${userIdMap.get(eventMessage.user)?.real_name}(${eventMessage.user}) in ${conversationContext} at ${eventMessage.ts}. Content: '${eventMessageText}'`;
|
||||
const text = `User ${userIdMap.get(eventMessage.user)?.real_name}(${eventMessage.user}) reacted with eyes emoji in ${conversationContext} at ${eventMessage.ts}. Content: '${eventMessageText}'`;
|
||||
|
||||
const permalinkResponse = await axios.get(
|
||||
`https://slack.com/api/chat.getPermalink?channel=${channel}&message_ts=${ts}`,
|
||||
@ -137,9 +136,10 @@ export const createActivityEvent = async (
|
||||
integrationAccountId: config.integrationAccountId,
|
||||
};
|
||||
|
||||
return createActivityMessage(activity);
|
||||
return [createActivityMessage(activity)];
|
||||
}
|
||||
return { message: `Processed activity from slack` };
|
||||
|
||||
return [];
|
||||
};
|
||||
|
||||
function getMentionUsers(message: string): string[] {
|
||||
|
||||
@ -13,13 +13,20 @@ export async function run(eventPayload: IntegrationEventPayload) {
|
||||
return await integrationCreate(eventPayload.eventBody);
|
||||
|
||||
case IntegrationEventType.IDENTIFY:
|
||||
return eventPayload.eventBody.event.user;
|
||||
return [
|
||||
{
|
||||
type: 'identifier',
|
||||
data:
|
||||
eventPayload.eventBody.event.event.user ||
|
||||
eventPayload.eventBody.event.event.message.user,
|
||||
},
|
||||
];
|
||||
|
||||
case IntegrationEventType.PROCESS:
|
||||
return createActivityEvent(eventPayload.eventBody.eventData, eventPayload.config);
|
||||
|
||||
default:
|
||||
return { message: `The event payload type is ${eventPayload.event}` };
|
||||
return [{ type: 'error', data: `The event payload type is ${eventPayload.event}` }];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user