diff --git a/apps/docs/editor/blocks/integrations/blink.mdx b/apps/docs/editor/blocks/integrations/blink.mdx index 988d54e21..a1f30b386 100644 --- a/apps/docs/editor/blocks/integrations/blink.mdx +++ b/apps/docs/editor/blocks/integrations/blink.mdx @@ -54,7 +54,6 @@ The "Send Feed Event" action allows you to create rich, interactive cards in you The Blink integration supports a rich variety of content types for your feed cards. For comprehensive UI options and examples, refer to the [official Blink CardKit documentation](https://developer.joinblink.com/docs/cardkit). - ### Targeting - **User IDs**: Specific users who should see this feed event diff --git a/apps/docs/openapi/builder.json b/apps/docs/openapi/builder.json index e32ecc51c..c5c9d7376 100644 --- a/apps/docs/openapi/builder.json +++ b/apps/docs/openapi/builder.json @@ -22285,6 +22285,26 @@ "required": [ "action" ] + }, + { + "type": "object", + "properties": { + "credentialsId": { + "type": "string" + }, + "action": { + "type": "string", + "enum": [ + "Redirect" + ] + }, + "url": { + "type": "string" + } + }, + "required": [ + "action" + ] } ] } diff --git a/apps/docs/openapi/viewer.json b/apps/docs/openapi/viewer.json index 3d5b2234e..41d11265a 100644 --- a/apps/docs/openapi/viewer.json +++ b/apps/docs/openapi/viewer.json @@ -13440,6 +13440,26 @@ "required": [ "action" ] + }, + { + "type": "object", + "properties": { + "credentialsId": { + "type": "string" + }, + "action": { + "type": "string", + "enum": [ + "Redirect" + ] + }, + "url": { + "type": "string" + } + }, + "required": [ + "action" + ] } ] } diff --git a/packages/bot-engine/src/forge/executeForgedBlock.ts b/packages/bot-engine/src/forge/executeForgedBlock.ts index da40c57b1..daa9abbf0 100644 --- a/packages/bot-engine/src/forge/executeForgedBlock.ts +++ b/packages/bot-engine/src/forge/executeForgedBlock.ts @@ -181,15 +181,17 @@ export const executeForgedBlock = async ( const clientSideActions: ExecuteIntegrationResponse["clientSideActions"] = []; if (action?.run?.web?.parseFunction) { - clientSideActions.push({ - type: "codeToExecute", - codeToExecute: action?.run?.web?.parseFunction({ - credentials: credentialsData ?? {}, - options: parsedOptions, - variables, - logs: logsStore, - }), + const codeToExecute = action?.run?.web?.parseFunction({ + credentials: credentialsData ?? {}, + options: parsedOptions, + variables, + logs: logsStore, }); + if (codeToExecute?.content) + clientSideActions.push({ + type: "codeToExecute", + codeToExecute, + }); } return { diff --git a/packages/forge/blocks/blink/src/actions/redirect.ts b/packages/forge/blocks/blink/src/actions/redirect.ts new file mode 100644 index 000000000..756e03ba3 --- /dev/null +++ b/packages/forge/blocks/blink/src/actions/redirect.ts @@ -0,0 +1,45 @@ +import { createAction, option } from "@typebot.io/forge"; +import { auth } from "../auth"; + +export const redirect = createAction({ + name: "Redirect", + auth, + options: option.object({ + url: option.string.optional().layout({ + label: "URL", + placeholder: "https://app.joinblink.com/#/hub/xxxx-xxxx", + }), + }), + run: { + web: { + parseFunction({ options: { url } }) { + return { + args: { + url: url ?? null, + }, + content: ` + if (!url) return; + const idMatch = url?.match(/([a-f0-9-]{36})$/); + if (!idMatch) return; + + const action = \`blink:folder?action=open&id=\${idMatch[1]}\`; + try { + if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openClientAction) { + window.webkit.messageHandlers.openClientAction.postMessage(action); + } else if (window.android && typeof window.android.openClientAction === 'function') { + window.android.openClientAction(action); + } else if (window.parent && window.parent !== window) { + console.log("posting message to parent"); + window.parent.postMessage({ functionName: 'openClientAction', args: [action] }, document.referrer); + } else { + window.open(url, "_blank"); + } + return false; + } catch (error) { + return false; + }`, + }; + }, + }, + }, +}); diff --git a/packages/forge/blocks/blink/src/index.ts b/packages/forge/blocks/blink/src/index.ts index 7251bc9db..c8a47837a 100644 --- a/packages/forge/blocks/blink/src/index.ts +++ b/packages/forge/blocks/blink/src/index.ts @@ -1,5 +1,6 @@ import { createBlock } from "@typebot.io/forge"; import { getUsers } from "./actions/getUsers"; +import { redirect } from "./actions/redirect"; import { sendFeedEvent } from "./actions/sendFeedEvent"; import { auth } from "./auth"; import { BlinkLogo } from "./logo"; @@ -10,6 +11,6 @@ export const blinkBlock = createBlock({ tags: ["CRM", "HR"], LightLogo: BlinkLogo, auth, - actions: [getUsers, sendFeedEvent], + actions: [getUsers, sendFeedEvent, redirect], docsUrl: "https://docs.typebot.io/editor/blocks/integrations/blink", }); diff --git a/packages/forge/core/src/types.ts b/packages/forge/core/src/types.ts index e20f3f01a..2b42db207 100644 --- a/packages/forge/core/src/types.ts +++ b/packages/forge/core/src/types.ts @@ -138,7 +138,7 @@ export type ActionDefinition< options: WithoutVariables & z.infer>; variables: VariableStore; logs: LogsStore; - }) => FunctionToExecute; + }) => FunctionToExecute | undefined; }; }; };