From eaf8024c84ba9a4d9f58a162bebe171e6a8e3fc7 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Mon, 27 Feb 2023 10:54:00 +0100 Subject: [PATCH] :pencil: Add API share instructions Closes #331 --- .../components/ApiPreviewInstructions.tsx | 124 ++++++++++-------- .../preview/components/PreviewDrawerBody.tsx | 2 +- .../publish/components/embeds/EmbedButton.tsx | 28 ++-- .../components/embeds/modals/ApiModal.tsx | 108 +++++++++++++++ 4 files changed, 198 insertions(+), 64 deletions(-) create mode 100644 apps/builder/src/features/publish/components/embeds/modals/ApiModal.tsx diff --git a/apps/builder/src/features/preview/components/ApiPreviewInstructions.tsx b/apps/builder/src/features/preview/components/ApiPreviewInstructions.tsx index a0577b703..b86d5b0e0 100644 --- a/apps/builder/src/features/preview/components/ApiPreviewInstructions.tsx +++ b/apps/builder/src/features/preview/components/ApiPreviewInstructions.tsx @@ -2,10 +2,17 @@ import { CodeEditor } from '@/components/CodeEditor' import { TextLink } from '@/components/TextLink' import { useEditor } from '@/features/editor/providers/EditorProvider' import { useTypebot } from '@/features/editor/providers/TypebotProvider' -import { Code, ListItem, OrderedList, Stack, Text } from '@chakra-ui/react' +import { + Code, + ListItem, + OrderedList, + Stack, + StackProps, + Text, +} from '@chakra-ui/react' import { env, getViewerUrl } from 'utils' -export const ApiPreviewInstructions = () => { +export const ApiPreviewInstructions = (props: StackProps) => { const { typebot } = useTypebot() const { startPreviewAtGroup } = useEditor() @@ -30,60 +37,69 @@ export const ApiPreviewInstructions = () => { }` return ( - - - All your requests need to be authenticated with an API token.{' '} - - See instructions - - . - - - - - To start the chat, send a POST request to - - - with the following JSON body: - - - - - The first response will contain a sessionId that you will - need for subsequent requests. - - - - - To send replies, send POST requests to - - - With the following JSON body: - - - Replace {''} with{' '} - sessionId. - - - - + + + All your requests need to be authenticated with an API token.{' '} + + See instructions + + . + + + + + To start the chat, send a POST request to + + + with the following JSON body: + + + + + The first response will contain a sessionId that you will + need for subsequent requests. + + + + + To send replies, send POST requests to + + + With the following JSON body: + + + Replace {''} with{' '} + sessionId. + + + + + + Check out the{' '} + + API reference + {' '} + for more information + + ) } diff --git a/apps/builder/src/features/preview/components/PreviewDrawerBody.tsx b/apps/builder/src/features/preview/components/PreviewDrawerBody.tsx index dc30d4c0e..3ec18d585 100644 --- a/apps/builder/src/features/preview/components/PreviewDrawerBody.tsx +++ b/apps/builder/src/features/preview/components/PreviewDrawerBody.tsx @@ -12,7 +12,7 @@ export const PreviewDrawerBody = ({ runtime }: Props) => { return } case 'API': { - return + return } } } diff --git a/apps/builder/src/features/publish/components/embeds/EmbedButton.tsx b/apps/builder/src/features/publish/components/embeds/EmbedButton.tsx index c7c11e67b..aee50a9b0 100644 --- a/apps/builder/src/features/publish/components/embeds/EmbedButton.tsx +++ b/apps/builder/src/features/publish/components/embeds/EmbedButton.tsx @@ -33,6 +33,8 @@ import { import { OtherModal } from './modals/OtherModal' import { ScriptIcon } from '@/features/blocks/logic/script' import { ScriptModal } from './modals/Script/ScriptModal' +import { CodeIcon } from '@/components/icons' +import { ApiModal } from './modals/ApiModal' export type ModalProps = { publicId: string @@ -123,15 +125,9 @@ export const integrationsList = [ ), (props: Pick) => ( - } - label="Script" - Modal={ScriptModal} + logo={} + label="API" + Modal={ApiModal} {...props} /> ), @@ -151,6 +147,20 @@ export const integrationsList = [ {...props} /> ), + (props: Pick) => ( + + } + label="Script" + Modal={ScriptModal} + {...props} + /> + ), (props: Pick) => ( } diff --git a/apps/builder/src/features/publish/components/embeds/modals/ApiModal.tsx b/apps/builder/src/features/publish/components/embeds/modals/ApiModal.tsx new file mode 100644 index 000000000..753debecd --- /dev/null +++ b/apps/builder/src/features/publish/components/embeds/modals/ApiModal.tsx @@ -0,0 +1,108 @@ +import { AlertInfo } from '@/components/AlertInfo' +import { CodeEditor } from '@/components/CodeEditor' +import { TextLink } from '@/components/TextLink' +import { + Modal, + ModalOverlay, + ModalContent, + ModalHeader, + Heading, + ModalCloseButton, + ModalBody, + OrderedList, + ListItem, + Code, + ModalFooter, + Text, + Stack, +} from '@chakra-ui/react' +import { env, getViewerUrl } from 'utils' +import { ModalProps } from '../EmbedButton' + +export const ApiModal = ({ + isPublished, + publicId, + isOpen, + onClose, +}: ModalProps): JSX.Element => { + const startParamsBody = `{ + "startParams": { + "typebot": "${publicId}", + } +}` + + const replyBody = `{ + "message": "This is my reply", + "sessionId": "" +}` + + return ( + + + + + API + + + + {!isPublished && ( + You need to publish your bot first. + )} + + + + + To start the chat, send a POST request to + + + with the following JSON body: + + + + + The first response will contain a sessionId that you + will need for subsequent requests. + + + + + To send replies, send POST requests to + + + With the following JSON body: + + + Replace {''} with{' '} + sessionId. + + + + + + Check out the{' '} + + API reference + {' '} + for more information + + + + + + ) +}