From da4005e160bbab1622d8b667f5a851b8009cb4db Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Tue, 29 Aug 2023 14:52:44 +0200 Subject: [PATCH] :bug: (embed) Make sure env.ts is not bundled in js embed lib --- .../webhook/queries/executeWebhookQuery.ts | 3 +- .../preview/api/sendWhatsAppInitialMessage.ts | 2 +- .../embeds/modals/FlutterFlowModal.tsx | 2 +- .../modals/IframeModal/IframeSnippet.tsx | 2 +- .../components/embeds/modals/NotionModal.tsx | 2 +- .../WhatsAppCredentialsModal.tsx | 3 +- .../WordpressStandardInstructions.tsx | 2 +- .../embeds/snippetParsers/shared.ts | 3 +- .../settings/components/SettingsPage.tsx | 2 +- apps/docs/openapi/builder/_spec_.json | 740 ++++++++++- apps/docs/openapi/chat/_spec_.json | 1100 ++++++++++++++++- apps/viewer/src/components/ErrorPage.tsx | 2 +- .../src/components/TypebotViewer.tsx | 3 +- packages/embeds/js/package.json | 2 +- packages/embeds/nextjs/package.json | 2 +- packages/embeds/react/package.json | 2 +- packages/lib/getViewerUrl.ts | 4 + packages/lib/telemetry/sendTelemetryEvent.ts | 1 - packages/lib/utils.ts | 4 - 19 files changed, 1813 insertions(+), 68 deletions(-) create mode 100644 packages/lib/getViewerUrl.ts diff --git a/apps/builder/src/features/blocks/integrations/webhook/queries/executeWebhookQuery.ts b/apps/builder/src/features/blocks/integrations/webhook/queries/executeWebhookQuery.ts index e12ead63c..4394057af 100644 --- a/apps/builder/src/features/blocks/integrations/webhook/queries/executeWebhookQuery.ts +++ b/apps/builder/src/features/blocks/integrations/webhook/queries/executeWebhookQuery.ts @@ -1,5 +1,6 @@ import { Variable, WebhookResponse } from '@typebot.io/schemas' -import { getViewerUrl, sendRequest } from '@typebot.io/lib' +import { sendRequest } from '@typebot.io/lib' +import { getViewerUrl } from '@typebot.io/lib/getViewerUrl' export const executeWebhook = ( typebotId: string, diff --git a/apps/builder/src/features/preview/api/sendWhatsAppInitialMessage.ts b/apps/builder/src/features/preview/api/sendWhatsAppInitialMessage.ts index 87b1827ca..360eab9d0 100644 --- a/apps/builder/src/features/preview/api/sendWhatsAppInitialMessage.ts +++ b/apps/builder/src/features/preview/api/sendWhatsAppInitialMessage.ts @@ -1,7 +1,7 @@ import { authenticatedProcedure } from '@/helpers/server/trpc' import { z } from 'zod' import got, { HTTPError } from 'got' -import { getViewerUrl } from '@typebot.io/lib' +import { getViewerUrl } from '@typebot.io/lib/getViewerUrl' import prisma from '@/lib/prisma' import { TRPCError } from '@trpc/server' diff --git a/apps/builder/src/features/publish/components/embeds/modals/FlutterFlowModal.tsx b/apps/builder/src/features/publish/components/embeds/modals/FlutterFlowModal.tsx index 925f5d513..97abaf29b 100644 --- a/apps/builder/src/features/publish/components/embeds/modals/FlutterFlowModal.tsx +++ b/apps/builder/src/features/publish/components/embeds/modals/FlutterFlowModal.tsx @@ -18,7 +18,7 @@ import { Text, Stack, } from '@chakra-ui/react' -import { getViewerUrl } from '@typebot.io/lib' +import { getViewerUrl } from '@typebot.io/lib/getViewerUrl' import { ModalProps } from '../EmbedButton' export const FlutterFlowModal = ({ diff --git a/apps/builder/src/features/publish/components/embeds/modals/IframeModal/IframeSnippet.tsx b/apps/builder/src/features/publish/components/embeds/modals/IframeModal/IframeSnippet.tsx index a601e15ef..2c3086b45 100644 --- a/apps/builder/src/features/publish/components/embeds/modals/IframeModal/IframeSnippet.tsx +++ b/apps/builder/src/features/publish/components/embeds/modals/IframeModal/IframeSnippet.tsx @@ -1,6 +1,6 @@ import { FlexProps } from '@chakra-ui/react' import { useTypebot } from '@/features/editor/providers/TypebotProvider' -import { getViewerUrl } from '@typebot.io/lib' +import { getViewerUrl } from '@typebot.io/lib/getViewerUrl' import { CodeEditor } from '@/components/inputs/CodeEditor' import prettier from 'prettier/standalone' import parserHtml from 'prettier/parser-html' diff --git a/apps/builder/src/features/publish/components/embeds/modals/NotionModal.tsx b/apps/builder/src/features/publish/components/embeds/modals/NotionModal.tsx index 4eaa289f8..f68bd120b 100644 --- a/apps/builder/src/features/publish/components/embeds/modals/NotionModal.tsx +++ b/apps/builder/src/features/publish/components/embeds/modals/NotionModal.tsx @@ -18,7 +18,7 @@ import { Text, Stack, } from '@chakra-ui/react' -import { getViewerUrl } from '@typebot.io/lib' +import { getViewerUrl } from '@typebot.io/lib/getViewerUrl' import { ModalProps } from '../EmbedButton' export const NotionModal = ({ diff --git a/apps/builder/src/features/publish/components/embeds/modals/WhatsAppModal/WhatsAppCredentialsModal.tsx b/apps/builder/src/features/publish/components/embeds/modals/WhatsAppModal/WhatsAppCredentialsModal.tsx index 4d8f058e5..cae7170de 100644 --- a/apps/builder/src/features/publish/components/embeds/modals/WhatsAppModal/WhatsAppCredentialsModal.tsx +++ b/apps/builder/src/features/publish/components/embeds/modals/WhatsAppModal/WhatsAppCredentialsModal.tsx @@ -40,7 +40,8 @@ import { InputRightElement, } from '@chakra-ui/react' import { env } from '@typebot.io/env' -import { getViewerUrl, isEmpty, isNotEmpty } from '@typebot.io/lib/utils' +import { isEmpty, isNotEmpty } from '@typebot.io/lib/utils' +import { getViewerUrl } from '@typebot.io/lib/getViewerUrl' import React, { useState } from 'react' const steps = [ diff --git a/apps/builder/src/features/publish/components/embeds/modals/WordpressModal/instructions/WordpressStandardInstructions.tsx b/apps/builder/src/features/publish/components/embeds/modals/WordpressModal/instructions/WordpressStandardInstructions.tsx index 4c95397fd..a8c98bd75 100644 --- a/apps/builder/src/features/publish/components/embeds/modals/WordpressModal/instructions/WordpressStandardInstructions.tsx +++ b/apps/builder/src/features/publish/components/embeds/modals/WordpressModal/instructions/WordpressStandardInstructions.tsx @@ -12,7 +12,7 @@ import { import { useState } from 'react' import { StandardSettings } from '../../../settings/StandardSettings' import { isCloudProdInstance } from '@/helpers/isCloudProdInstance' -import { getViewerUrl } from '@typebot.io/lib' +import { getViewerUrl } from '@typebot.io/lib/getViewerUrl' type Props = { publicId: string diff --git a/apps/builder/src/features/publish/components/embeds/snippetParsers/shared.ts b/apps/builder/src/features/publish/components/embeds/snippetParsers/shared.ts index 8b50fda2a..f283c97e4 100644 --- a/apps/builder/src/features/publish/components/embeds/snippetParsers/shared.ts +++ b/apps/builder/src/features/publish/components/embeds/snippetParsers/shared.ts @@ -1,7 +1,8 @@ import { BotProps } from '@typebot.io/nextjs' import parserBabel from 'prettier/parser-babel' import prettier from 'prettier/standalone' -import { getViewerUrl, isDefined } from '@typebot.io/lib' +import { isDefined } from '@typebot.io/lib' +import { getViewerUrl } from '@typebot.io/lib/getViewerUrl' import { Typebot } from '@typebot.io/schemas' import { isCloudProdInstance } from '@/helpers/isCloudProdInstance' import packageJson from '../../../../../../../../packages/embeds/js/package.json' diff --git a/apps/builder/src/features/settings/components/SettingsPage.tsx b/apps/builder/src/features/settings/components/SettingsPage.tsx index 1cb72b66a..a6f791f25 100644 --- a/apps/builder/src/features/settings/components/SettingsPage.tsx +++ b/apps/builder/src/features/settings/components/SettingsPage.tsx @@ -1,7 +1,7 @@ import { Seo } from '@/components/Seo' import { Flex } from '@chakra-ui/react' import { Standard } from '@typebot.io/nextjs' -import { getViewerUrl } from '@typebot.io/lib' +import { getViewerUrl } from '@typebot.io/lib/getViewerUrl' import { SettingsSideMenu } from './SettingsSideMenu' import { TypebotHeader } from '@/features/editor/components/TypebotHeader' import { useTypebot } from '@/features/editor/providers/TypebotProvider' diff --git a/apps/docs/openapi/builder/_spec_.json b/apps/docs/openapi/builder/_spec_.json index 7170e06cb..c05210347 100644 --- a/apps/docs/openapi/builder/_spec_.json +++ b/apps/docs/openapi/builder/_spec_.json @@ -14,6 +14,9 @@ "post": { "operationId": "processTelemetryEvent", "description": "Only used for the cloud version of Typebot. It's the way it processes telemetry events and inject it to thrid-party services.", + "tags": [ + "Telemetry" + ], "requestBody": { "required": true, "content": { @@ -1985,7 +1988,9 @@ "Tomorrow", "Random ID", "Moment of the day", - "Map item with same index" + "Map item with same index", + "Phone number", + "Contact name" ] }, "mapListItemParams": { @@ -2562,8 +2567,7 @@ "required": [ "id" ], - "additionalProperties": false, - "description": "Deprecated. Use `filter` instead." + "additionalProperties": false } } }, @@ -2609,8 +2613,7 @@ "required": [ "id" ], - "additionalProperties": false, - "description": "Deprecated. Use `filter` instead." + "additionalProperties": false } }, "referenceCell": { @@ -6270,7 +6273,9 @@ "Tomorrow", "Random ID", "Moment of the day", - "Map item with same index" + "Map item with same index", + "Phone number", + "Contact name" ] }, "mapListItemParams": { @@ -6847,8 +6852,7 @@ "required": [ "id" ], - "additionalProperties": false, - "description": "Deprecated. Use `filter` instead." + "additionalProperties": false } } }, @@ -6894,8 +6898,7 @@ "required": [ "id" ], - "additionalProperties": false, - "description": "Deprecated. Use `filter` instead." + "additionalProperties": false } }, "referenceCell": { @@ -8432,6 +8435,67 @@ } }, "additionalProperties": false + }, + "whatsApp": { + "type": "object", + "properties": { + "credentialsId": { + "type": "string" + }, + "startCondition": { + "type": "object", + "properties": { + "logicalOperator": { + "type": "string", + "enum": [ + "OR", + "AND" + ] + }, + "comparisons": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "comparisonOperator": { + "type": "string", + "enum": [ + "Equal to", + "Not equal", + "Contains", + "Does not contain", + "Greater than", + "Less than", + "Is set", + "Is empty", + "Starts with", + "Ends with", + "Matches regex", + "Does not match regex" + ] + }, + "value": { + "type": "string" + } + }, + "required": [ + "id" + ], + "additionalProperties": false + } + } + }, + "required": [ + "logicalOperator", + "comparisons" + ], + "additionalProperties": false + } + }, + "additionalProperties": false } }, "required": [ @@ -10129,7 +10193,9 @@ "Tomorrow", "Random ID", "Moment of the day", - "Map item with same index" + "Map item with same index", + "Phone number", + "Contact name" ] }, "mapListItemParams": { @@ -10706,8 +10772,7 @@ "required": [ "id" ], - "additionalProperties": false, - "description": "Deprecated. Use `filter` instead." + "additionalProperties": false } } }, @@ -10753,8 +10818,7 @@ "required": [ "id" ], - "additionalProperties": false, - "description": "Deprecated. Use `filter` instead." + "additionalProperties": false } }, "referenceCell": { @@ -12380,6 +12444,67 @@ } }, "additionalProperties": false + }, + "whatsApp": { + "type": "object", + "properties": { + "credentialsId": { + "type": "string" + }, + "startCondition": { + "type": "object", + "properties": { + "logicalOperator": { + "type": "string", + "enum": [ + "OR", + "AND" + ] + }, + "comparisons": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "comparisonOperator": { + "type": "string", + "enum": [ + "Equal to", + "Not equal", + "Contains", + "Does not contain", + "Greater than", + "Less than", + "Is set", + "Is empty", + "Starts with", + "Ends with", + "Matches regex", + "Does not match regex" + ] + }, + "value": { + "type": "string" + } + }, + "required": [ + "id" + ], + "additionalProperties": false + } + } + }, + "required": [ + "logicalOperator", + "comparisons" + ], + "additionalProperties": false + } + }, + "additionalProperties": false } }, "required": [ @@ -12451,6 +12576,10 @@ }, "isClosed": { "type": "boolean" + }, + "whatsAppPhoneNumberId": { + "type": "string", + "nullable": true } }, "required": [ @@ -12472,7 +12601,8 @@ "workspaceId", "resultsTablePreferences", "isArchived", - "isClosed" + "isClosed", + "whatsAppPhoneNumberId" ], "additionalProperties": false } @@ -14123,7 +14253,9 @@ "Tomorrow", "Random ID", "Moment of the day", - "Map item with same index" + "Map item with same index", + "Phone number", + "Contact name" ] }, "mapListItemParams": { @@ -14700,8 +14832,7 @@ "required": [ "id" ], - "additionalProperties": false, - "description": "Deprecated. Use `filter` instead." + "additionalProperties": false } } }, @@ -14747,8 +14878,7 @@ "required": [ "id" ], - "additionalProperties": false, - "description": "Deprecated. Use `filter` instead." + "additionalProperties": false } }, "referenceCell": { @@ -16285,6 +16415,67 @@ } }, "additionalProperties": false + }, + "whatsApp": { + "type": "object", + "properties": { + "credentialsId": { + "type": "string" + }, + "startCondition": { + "type": "object", + "properties": { + "logicalOperator": { + "type": "string", + "enum": [ + "OR", + "AND" + ] + }, + "comparisons": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "comparisonOperator": { + "type": "string", + "enum": [ + "Equal to", + "Not equal", + "Contains", + "Does not contain", + "Greater than", + "Less than", + "Is set", + "Is empty", + "Starts with", + "Ends with", + "Matches regex", + "Does not match regex" + ] + }, + "value": { + "type": "string" + } + }, + "required": [ + "id" + ], + "additionalProperties": false + } + } + }, + "required": [ + "logicalOperator", + "comparisons" + ], + "additionalProperties": false + } + }, + "additionalProperties": false } }, "required": [ @@ -16423,6 +16614,10 @@ }, "isClosed": { "type": "boolean" + }, + "whatsAppPhoneNumberId": { + "type": "string", + "nullable": true } }, "additionalProperties": false @@ -17998,7 +18193,9 @@ "Tomorrow", "Random ID", "Moment of the day", - "Map item with same index" + "Map item with same index", + "Phone number", + "Contact name" ] }, "mapListItemParams": { @@ -18575,8 +18772,7 @@ "required": [ "id" ], - "additionalProperties": false, - "description": "Deprecated. Use `filter` instead." + "additionalProperties": false } } }, @@ -18622,8 +18818,7 @@ "required": [ "id" ], - "additionalProperties": false, - "description": "Deprecated. Use `filter` instead." + "additionalProperties": false } }, "referenceCell": { @@ -20249,6 +20444,67 @@ } }, "additionalProperties": false + }, + "whatsApp": { + "type": "object", + "properties": { + "credentialsId": { + "type": "string" + }, + "startCondition": { + "type": "object", + "properties": { + "logicalOperator": { + "type": "string", + "enum": [ + "OR", + "AND" + ] + }, + "comparisons": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "comparisonOperator": { + "type": "string", + "enum": [ + "Equal to", + "Not equal", + "Contains", + "Does not contain", + "Greater than", + "Less than", + "Is set", + "Is empty", + "Starts with", + "Ends with", + "Matches regex", + "Does not match regex" + ] + }, + "value": { + "type": "string" + } + }, + "required": [ + "id" + ], + "additionalProperties": false + } + } + }, + "required": [ + "logicalOperator", + "comparisons" + ], + "additionalProperties": false + } + }, + "additionalProperties": false } }, "required": [ @@ -20320,6 +20576,10 @@ }, "isClosed": { "type": "boolean" + }, + "whatsAppPhoneNumberId": { + "type": "string", + "nullable": true } }, "required": [ @@ -20341,7 +20601,8 @@ "workspaceId", "resultsTablePreferences", "isArchived", - "isClosed" + "isClosed", + "whatsAppPhoneNumberId" ], "additionalProperties": false } @@ -21927,7 +22188,9 @@ "Tomorrow", "Random ID", "Moment of the day", - "Map item with same index" + "Map item with same index", + "Phone number", + "Contact name" ] }, "mapListItemParams": { @@ -22504,8 +22767,7 @@ "required": [ "id" ], - "additionalProperties": false, - "description": "Deprecated. Use `filter` instead." + "additionalProperties": false } } }, @@ -22551,8 +22813,7 @@ "required": [ "id" ], - "additionalProperties": false, - "description": "Deprecated. Use `filter` instead." + "additionalProperties": false } }, "referenceCell": { @@ -24178,6 +24439,67 @@ } }, "additionalProperties": false + }, + "whatsApp": { + "type": "object", + "properties": { + "credentialsId": { + "type": "string" + }, + "startCondition": { + "type": "object", + "properties": { + "logicalOperator": { + "type": "string", + "enum": [ + "OR", + "AND" + ] + }, + "comparisons": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "comparisonOperator": { + "type": "string", + "enum": [ + "Equal to", + "Not equal", + "Contains", + "Does not contain", + "Greater than", + "Less than", + "Is set", + "Is empty", + "Starts with", + "Ends with", + "Matches regex", + "Does not match regex" + ] + }, + "value": { + "type": "string" + } + }, + "required": [ + "id" + ], + "additionalProperties": false + } + } + }, + "required": [ + "logicalOperator", + "comparisons" + ], + "additionalProperties": false + } + }, + "additionalProperties": false } }, "required": [ @@ -24249,6 +24571,10 @@ }, "isClosed": { "type": "boolean" + }, + "whatsAppPhoneNumberId": { + "type": "string", + "nullable": true } }, "required": [ @@ -24270,7 +24596,8 @@ "workspaceId", "resultsTablePreferences", "isArchived", - "isClosed" + "isClosed", + "whatsAppPhoneNumberId" ], "additionalProperties": false }, @@ -25919,7 +26246,9 @@ "Tomorrow", "Random ID", "Moment of the day", - "Map item with same index" + "Map item with same index", + "Phone number", + "Contact name" ] }, "mapListItemParams": { @@ -26496,8 +26825,7 @@ "required": [ "id" ], - "additionalProperties": false, - "description": "Deprecated. Use `filter` instead." + "additionalProperties": false } } }, @@ -26543,8 +26871,7 @@ "required": [ "id" ], - "additionalProperties": false, - "description": "Deprecated. Use `filter` instead." + "additionalProperties": false } }, "referenceCell": { @@ -28166,6 +28493,67 @@ } }, "additionalProperties": false + }, + "whatsApp": { + "type": "object", + "properties": { + "credentialsId": { + "type": "string" + }, + "startCondition": { + "type": "object", + "properties": { + "logicalOperator": { + "type": "string", + "enum": [ + "OR", + "AND" + ] + }, + "comparisons": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "comparisonOperator": { + "type": "string", + "enum": [ + "Equal to", + "Not equal", + "Contains", + "Does not contain", + "Greater than", + "Less than", + "Is set", + "Is empty", + "Starts with", + "Ends with", + "Matches regex", + "Does not match regex" + ] + }, + "value": { + "type": "string" + } + }, + "required": [ + "id" + ], + "additionalProperties": false + } + } + }, + "required": [ + "logicalOperator", + "comparisons" + ], + "additionalProperties": false + } + }, + "additionalProperties": false } }, "required": [ @@ -29968,6 +30356,46 @@ "name" ], "additionalProperties": false + }, + { + "type": "object", + "properties": { + "data": { + "type": "object", + "properties": { + "systemUserAccessToken": { + "type": "string" + }, + "phoneNumberId": { + "type": "string" + } + }, + "required": [ + "systemUserAccessToken", + "phoneNumberId" + ], + "additionalProperties": false + }, + "type": { + "type": "string", + "enum": [ + "whatsApp" + ] + }, + "workspaceId": { + "type": "string" + }, + "name": { + "type": "string" + } + }, + "required": [ + "data", + "type", + "workspaceId", + "name" + ], + "additionalProperties": false } ] } @@ -30037,15 +30465,25 @@ { "anyOf": [ { - "type": "string", - "enum": [ - "stripe" + "anyOf": [ + { + "type": "string", + "enum": [ + "stripe" + ] + }, + { + "type": "string", + "enum": [ + "smtp" + ] + } ] }, { "type": "string", "enum": [ - "smtp" + "google sheets" ] } ] @@ -30053,7 +30491,7 @@ { "type": "string", "enum": [ - "google sheets" + "openai" ] } ] @@ -30061,7 +30499,7 @@ { "type": "string", "enum": [ - "openai" + "whatsApp" ] } ] @@ -31347,6 +31785,220 @@ } } } + }, + "/whatsapp/phoneNumber": { + "get": { + "operationId": "whatsApp-getPhoneNumber", + "security": [ + { + "Authorization": [] + } + ], + "parameters": [ + { + "name": "credentialsId", + "in": "query", + "required": false, + "schema": { + "type": "string" + } + }, + { + "name": "systemToken", + "in": "query", + "required": false, + "schema": { + "type": "string" + } + }, + { + "name": "phoneNumberId", + "in": "query", + "required": false, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + }, + "required": [ + "id", + "name" + ], + "additionalProperties": false + } + } + } + }, + "default": { + "$ref": "#/components/responses/error" + } + } + } + }, + "/whatsapp/systemToken": { + "get": { + "operationId": "whatsApp-getSystemTokenInfo", + "security": [ + { + "Authorization": [] + } + ], + "parameters": [ + { + "name": "token", + "in": "query", + "required": false, + "schema": { + "type": "string" + } + }, + { + "name": "credentialsId", + "in": "query", + "required": false, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "appId": { + "type": "string" + }, + "appName": { + "type": "string" + }, + "expiresAt": { + "type": "number" + }, + "scopes": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "appId", + "appName", + "expiresAt", + "scopes" + ], + "additionalProperties": false + } + } + } + }, + "default": { + "$ref": "#/components/responses/error" + } + } + } + }, + "/whatsapp/phoneNumber/{phoneNumberDisplayName}/available": { + "get": { + "operationId": "whatsApp-verifyIfPhoneNumberAvailable", + "security": [ + { + "Authorization": [] + } + ], + "parameters": [ + { + "name": "phoneNumberDisplayName", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string", + "enum": [ + "available", + "taken" + ] + } + }, + "required": [ + "message" + ], + "additionalProperties": false + } + } + } + }, + "default": { + "$ref": "#/components/responses/error" + } + } + } + }, + "/verficiationTokens": { + "post": { + "operationId": "whatsApp-generateVerificationToken", + "security": [ + { + "Authorization": [] + } + ], + "parameters": [], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "verificationToken": { + "type": "string" + } + }, + "required": [ + "verificationToken" + ], + "additionalProperties": false + } + } + } + }, + "default": { + "$ref": "#/components/responses/error" + } + } + } } }, "components": { diff --git a/apps/docs/openapi/chat/_spec_.json b/apps/docs/openapi/chat/_spec_.json index 4ac025170..a57712ffd 100644 --- a/apps/docs/openapi/chat/_spec_.json +++ b/apps/docs/openapi/chat/_spec_.json @@ -1571,7 +1571,9 @@ "Tomorrow", "Random ID", "Moment of the day", - "Map item with same index" + "Map item with same index", + "Phone number", + "Contact name" ] }, "mapListItemParams": { @@ -2148,8 +2150,7 @@ "required": [ "id" ], - "additionalProperties": false, - "description": "Deprecated. Use `filter` instead." + "additionalProperties": false } } }, @@ -2195,8 +2196,7 @@ "required": [ "id" ], - "additionalProperties": false, - "description": "Deprecated. Use `filter` instead." + "additionalProperties": false } }, "referenceCell": { @@ -3654,6 +3654,67 @@ } }, "additionalProperties": false + }, + "whatsApp": { + "type": "object", + "properties": { + "credentialsId": { + "type": "string" + }, + "startCondition": { + "type": "object", + "properties": { + "logicalOperator": { + "type": "string", + "enum": [ + "OR", + "AND" + ] + }, + "comparisons": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "comparisonOperator": { + "type": "string", + "enum": [ + "Equal to", + "Not equal", + "Contains", + "Does not contain", + "Greater than", + "Less than", + "Is set", + "Is empty", + "Starts with", + "Ends with", + "Matches regex", + "Does not match regex" + ] + }, + "value": { + "type": "string" + } + }, + "required": [ + "id" + ], + "additionalProperties": false + } + } + }, + "required": [ + "logicalOperator", + "comparisons" + ], + "additionalProperties": false + } + }, + "additionalProperties": false } }, "required": [ @@ -3865,6 +3926,10 @@ "isStreamEnabled": { "type": "boolean", "description": "Set this to `true` if you intend to stream OpenAI completions on a client." + }, + "isOnlyRegistering": { + "type": "boolean", + "description": "If set to `true`, it will only register the session and not start the chat. This is used for other chat platform integration as it can require a session to be registered before sending the first message." } }, "required": [ @@ -5987,6 +6052,67 @@ } }, "additionalProperties": false + }, + "whatsApp": { + "type": "object", + "properties": { + "credentialsId": { + "type": "string" + }, + "startCondition": { + "type": "object", + "properties": { + "logicalOperator": { + "type": "string", + "enum": [ + "OR", + "AND" + ] + }, + "comparisons": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "comparisonOperator": { + "type": "string", + "enum": [ + "Equal to", + "Not equal", + "Contains", + "Does not contain", + "Greater than", + "Less than", + "Is set", + "Is empty", + "Starts with", + "Ends with", + "Matches regex", + "Does not match regex" + ] + }, + "value": { + "type": "string" + } + }, + "required": [ + "id" + ], + "additionalProperties": false + } + } + }, + "required": [ + "logicalOperator", + "comparisons" + ], + "additionalProperties": false + } + }, + "additionalProperties": false } }, "required": [ @@ -6185,6 +6311,970 @@ } } } + }, + "/whatsapp/preview/webhook": { + "get": { + "operationId": "whatsAppRouter-subscribePreviewWebhook", + "summary": "WhatsApp", + "parameters": [ + { + "name": "hub.challenge", + "in": "query", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "hub.verify_token", + "in": "query", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "number" + } + } + } + }, + "default": { + "$ref": "#/components/responses/error" + } + } + }, + "post": { + "operationId": "whatsAppRouter-receiveMessagePreview", + "summary": "WhatsApp", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "entry": { + "type": "array", + "items": { + "type": "object", + "properties": { + "changes": { + "type": "array", + "items": { + "type": "object", + "properties": { + "value": { + "type": "object", + "properties": { + "contacts": { + "type": "array", + "items": { + "type": "object", + "properties": { + "profile": { + "type": "object", + "properties": { + "name": { + "type": "string" + } + }, + "required": [ + "name" + ], + "additionalProperties": false + } + }, + "required": [ + "profile" + ], + "additionalProperties": false + } + }, + "metadata": { + "type": "object", + "properties": { + "display_phone_number": { + "type": "string" + } + }, + "required": [ + "display_phone_number" + ], + "additionalProperties": false + }, + "messages": { + "type": "array", + "items": { + "anyOf": [ + { + "type": "object", + "properties": { + "from": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "text" + ] + }, + "text": { + "type": "object", + "properties": { + "body": { + "type": "string" + } + }, + "required": [ + "body" + ], + "additionalProperties": false + }, + "timestamp": { + "type": "string" + } + }, + "required": [ + "from", + "type", + "text", + "timestamp" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "from": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "button" + ] + }, + "button": { + "type": "object", + "properties": { + "text": { + "type": "string" + }, + "payload": { + "type": "string" + } + }, + "required": [ + "text", + "payload" + ], + "additionalProperties": false + }, + "timestamp": { + "type": "string" + } + }, + "required": [ + "from", + "type", + "button", + "timestamp" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "from": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "interactive" + ] + }, + "interactive": { + "type": "object", + "properties": { + "button_reply": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "title": { + "type": "string" + } + }, + "required": [ + "id", + "title" + ], + "additionalProperties": false + } + }, + "required": [ + "button_reply" + ], + "additionalProperties": false + }, + "timestamp": { + "type": "string" + } + }, + "required": [ + "from", + "type", + "interactive", + "timestamp" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "from": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "image" + ] + }, + "image": { + "type": "object", + "properties": { + "id": { + "type": "string" + } + }, + "required": [ + "id" + ], + "additionalProperties": false + }, + "timestamp": { + "type": "string" + } + }, + "required": [ + "from", + "type", + "image", + "timestamp" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "from": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "video" + ] + }, + "video": { + "type": "object", + "properties": { + "id": { + "type": "string" + } + }, + "required": [ + "id" + ], + "additionalProperties": false + }, + "timestamp": { + "type": "string" + } + }, + "required": [ + "from", + "type", + "video", + "timestamp" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "from": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "audio" + ] + }, + "audio": { + "type": "object", + "properties": { + "id": { + "type": "string" + } + }, + "required": [ + "id" + ], + "additionalProperties": false + }, + "timestamp": { + "type": "string" + } + }, + "required": [ + "from", + "type", + "audio", + "timestamp" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "from": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "document" + ] + }, + "document": { + "type": "object", + "properties": { + "id": { + "type": "string" + } + }, + "required": [ + "id" + ], + "additionalProperties": false + }, + "timestamp": { + "type": "string" + } + }, + "required": [ + "from", + "type", + "document", + "timestamp" + ], + "additionalProperties": false + } + ] + } + } + }, + "required": [ + "metadata" + ], + "additionalProperties": false + } + }, + "required": [ + "value" + ], + "additionalProperties": false + } + } + }, + "required": [ + "changes" + ], + "additionalProperties": false + } + } + }, + "required": [ + "entry" + ], + "additionalProperties": false + } + } + } + }, + "parameters": [], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string" + } + }, + "required": [ + "message" + ], + "additionalProperties": false + } + } + } + }, + "default": { + "$ref": "#/components/responses/error" + } + } + } + }, + "/workspaces/{workspaceId}/whatsapp/phoneNumbers/{phoneNumberId}/webhook": { + "get": { + "operationId": "whatsAppRouter-subscribeWebhook", + "summary": "Subscribe WhatsApp webhook", + "security": [ + { + "Authorization": [] + } + ], + "parameters": [ + { + "name": "workspaceId", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "phoneNumberId", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "hub.challenge", + "in": "query", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "hub.verify_token", + "in": "query", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "number" + } + } + } + }, + "default": { + "$ref": "#/components/responses/error" + } + } + }, + "post": { + "operationId": "whatsAppRouter-receiveMessage", + "summary": "Receive WhatsApp Message", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "entry": { + "type": "array", + "items": { + "type": "object", + "properties": { + "changes": { + "type": "array", + "items": { + "type": "object", + "properties": { + "value": { + "type": "object", + "properties": { + "contacts": { + "type": "array", + "items": { + "type": "object", + "properties": { + "profile": { + "type": "object", + "properties": { + "name": { + "type": "string" + } + }, + "required": [ + "name" + ], + "additionalProperties": false + } + }, + "required": [ + "profile" + ], + "additionalProperties": false + } + }, + "metadata": { + "type": "object", + "properties": { + "display_phone_number": { + "type": "string" + } + }, + "required": [ + "display_phone_number" + ], + "additionalProperties": false + }, + "messages": { + "type": "array", + "items": { + "anyOf": [ + { + "type": "object", + "properties": { + "from": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "text" + ] + }, + "text": { + "type": "object", + "properties": { + "body": { + "type": "string" + } + }, + "required": [ + "body" + ], + "additionalProperties": false + }, + "timestamp": { + "type": "string" + } + }, + "required": [ + "from", + "type", + "text", + "timestamp" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "from": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "button" + ] + }, + "button": { + "type": "object", + "properties": { + "text": { + "type": "string" + }, + "payload": { + "type": "string" + } + }, + "required": [ + "text", + "payload" + ], + "additionalProperties": false + }, + "timestamp": { + "type": "string" + } + }, + "required": [ + "from", + "type", + "button", + "timestamp" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "from": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "interactive" + ] + }, + "interactive": { + "type": "object", + "properties": { + "button_reply": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "title": { + "type": "string" + } + }, + "required": [ + "id", + "title" + ], + "additionalProperties": false + } + }, + "required": [ + "button_reply" + ], + "additionalProperties": false + }, + "timestamp": { + "type": "string" + } + }, + "required": [ + "from", + "type", + "interactive", + "timestamp" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "from": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "image" + ] + }, + "image": { + "type": "object", + "properties": { + "id": { + "type": "string" + } + }, + "required": [ + "id" + ], + "additionalProperties": false + }, + "timestamp": { + "type": "string" + } + }, + "required": [ + "from", + "type", + "image", + "timestamp" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "from": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "video" + ] + }, + "video": { + "type": "object", + "properties": { + "id": { + "type": "string" + } + }, + "required": [ + "id" + ], + "additionalProperties": false + }, + "timestamp": { + "type": "string" + } + }, + "required": [ + "from", + "type", + "video", + "timestamp" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "from": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "audio" + ] + }, + "audio": { + "type": "object", + "properties": { + "id": { + "type": "string" + } + }, + "required": [ + "id" + ], + "additionalProperties": false + }, + "timestamp": { + "type": "string" + } + }, + "required": [ + "from", + "type", + "audio", + "timestamp" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "from": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "document" + ] + }, + "document": { + "type": "object", + "properties": { + "id": { + "type": "string" + } + }, + "required": [ + "id" + ], + "additionalProperties": false + }, + "timestamp": { + "type": "string" + } + }, + "required": [ + "from", + "type", + "document", + "timestamp" + ], + "additionalProperties": false + } + ] + } + } + }, + "required": [ + "metadata" + ], + "additionalProperties": false + } + }, + "required": [ + "value" + ], + "additionalProperties": false + } + } + }, + "required": [ + "changes" + ], + "additionalProperties": false + } + } + }, + "required": [ + "entry" + ], + "additionalProperties": false + } + } + } + }, + "parameters": [ + { + "name": "workspaceId", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "phoneNumberId", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string" + } + }, + "required": [ + "message" + ], + "additionalProperties": false + } + } + } + }, + "default": { + "$ref": "#/components/responses/error" + } + } + } + }, + "/typebots/{typebotId}/whatsapp/start-preview": { + "post": { + "operationId": "whatsAppRouter-startWhatsAppPreview", + "summary": "Start WhatsApp Preview", + "security": [ + { + "Authorization": [] + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "to": { + "type": "string", + "minLength": 1 + }, + "startGroupId": { + "type": "string" + } + }, + "required": [ + "to" + ], + "additionalProperties": false + } + } + } + }, + "parameters": [ + { + "name": "typebotId", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string" + } + }, + "required": [ + "message" + ], + "additionalProperties": false + } + } + } + }, + "default": { + "$ref": "#/components/responses/error" + } + } + } } }, "components": { diff --git a/apps/viewer/src/components/ErrorPage.tsx b/apps/viewer/src/components/ErrorPage.tsx index 4d3fbea22..cd2bc438e 100644 --- a/apps/viewer/src/components/ErrorPage.tsx +++ b/apps/viewer/src/components/ErrorPage.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { getViewerUrl } from '@typebot.io/lib' +import { getViewerUrl } from '@typebot.io/lib/getViewerUrl' export const ErrorPage = ({ error }: { error: Error }) => { return ( diff --git a/packages/deprecated/bot-engine/src/components/TypebotViewer.tsx b/packages/deprecated/bot-engine/src/components/TypebotViewer.tsx index 8e6da4a3a..6582e3638 100644 --- a/packages/deprecated/bot-engine/src/components/TypebotViewer.tsx +++ b/packages/deprecated/bot-engine/src/components/TypebotViewer.tsx @@ -14,7 +14,8 @@ import { } from '@typebot.io/schemas' import { Log } from '@typebot.io/prisma' import { LiteBadge } from './LiteBadge' -import { getViewerUrl, isEmpty, isNotEmpty } from '@typebot.io/lib' +import { isNotEmpty } from '@typebot.io/lib' +import { getViewerUrl } from '@typebot.io/lib/getViewerUrl' export type TypebotViewerProps = { typebot: Omit diff --git a/packages/embeds/js/package.json b/packages/embeds/js/package.json index 40fb0f0bc..bf6297c01 100644 --- a/packages/embeds/js/package.json +++ b/packages/embeds/js/package.json @@ -1,6 +1,6 @@ { "name": "@typebot.io/js", - "version": "0.1.21", + "version": "0.1.22", "description": "Javascript library to display typebots on your website", "type": "module", "main": "dist/index.js", diff --git a/packages/embeds/nextjs/package.json b/packages/embeds/nextjs/package.json index f6a6340fa..0c94e53ef 100644 --- a/packages/embeds/nextjs/package.json +++ b/packages/embeds/nextjs/package.json @@ -1,6 +1,6 @@ { "name": "@typebot.io/nextjs", - "version": "0.1.21", + "version": "0.1.22", "description": "Convenient library to display typebots on your Next.js website", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/embeds/react/package.json b/packages/embeds/react/package.json index e504ee354..7552449bf 100644 --- a/packages/embeds/react/package.json +++ b/packages/embeds/react/package.json @@ -1,6 +1,6 @@ { "name": "@typebot.io/react", - "version": "0.1.21", + "version": "0.1.22", "description": "Convenient library to display typebots on your React app", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/lib/getViewerUrl.ts b/packages/lib/getViewerUrl.ts new file mode 100644 index 000000000..26ff77fdb --- /dev/null +++ b/packages/lib/getViewerUrl.ts @@ -0,0 +1,4 @@ +import { env } from '@typebot.io/env' + +export const getViewerUrl = () => + env.NEXT_PUBLIC_VIEWER_INTERNAL_URL ?? env.NEXT_PUBLIC_VIEWER_URL[0] diff --git a/packages/lib/telemetry/sendTelemetryEvent.ts b/packages/lib/telemetry/sendTelemetryEvent.ts index 05de19d26..24ef2b52a 100644 --- a/packages/lib/telemetry/sendTelemetryEvent.ts +++ b/packages/lib/telemetry/sendTelemetryEvent.ts @@ -1,6 +1,5 @@ import got from 'got' import { TelemetryEvent } from '@typebot.io/schemas/features/telemetry' -import { isNotEmpty } from '../utils' import { env } from '@typebot.io/env' export const sendTelemetryEvents = async (events: TelemetryEvent[]) => { diff --git a/packages/lib/utils.ts b/packages/lib/utils.ts index 058adcbd6..37eef5a63 100644 --- a/packages/lib/utils.ts +++ b/packages/lib/utils.ts @@ -19,7 +19,6 @@ import { BubbleBlockType } from '@typebot.io/schemas/features/blocks/bubbles/enu import { LogicBlockType } from '@typebot.io/schemas/features/blocks/logic/enums' import { IntegrationBlockType } from '@typebot.io/schemas/features/blocks/integrations/enums' import { PictureChoiceBlock } from '@typebot.io/schemas/features/blocks/inputs/pictureChoice' -import { env } from '@typebot.io/env' export const sendRequest = async ( params: @@ -257,9 +256,6 @@ export const hasValue = ( value !== 'undefined' && value !== 'null' -export const getViewerUrl = () => - env.NEXT_PUBLIC_VIEWER_INTERNAL_URL ?? env.NEXT_PUBLIC_VIEWER_URL[0] - export const parseNumberWithCommas = (num: number) => num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')