From Bright Pattern Documentation
Jump to: navigation, search
This page contains changes which are not marked for translation.
• 5.19

startChat

Create a new SMS interaction.

Request

Syntax

startSMSChat(channel: ChatChannelType, address: string, initialObject?: InteractionAssociatedObject): Promise<OperationResult<null>>

Where:

type ChatChannelType =

  |

    "sms" |

type InteractionAssociatedObject = {

    id: string

    type: string

    displayName: string

    displayType: string

    customFields: Record<string, string>

}

Parameters

Parameters Parameter Values Data Type Optional/Required Description
channel String Required Allows you to define one of the supported chat channels.
address String Required Allows you to define the phone number or the user id with which you want to start a chat.
initialObject
  • id: string
  • type: string
  • displayName: string
  • displayType: string
  • customFields: Record<string, string>
Optional Allows you to specify an object associated with this chat upon initialization. For example, on a click-to-chat action from a contact, you can send info about that contact here.

Example Request

    startChatButton.onclick = () => {

        const chatChannel = chatChannelInput.value

        const chatAddress = chatAddressInput.value

        let associatedObject: InteractionAssociatedObject | undefined = undefined

        const associatedObjectStr = associatedObjectTextarea.value

        if (associatedObjectStr) {

            try {

                associatedObject = JSON.parse(associatedObjectStr)

            } catch (e) {

                alert('You have syntax error in the associated object structure. Cannot parse JSON.')

                return

            }

        }

        adApi.startChat(chatChannel as any, chatAddress, associatedObject)

    }

Return Value

null


< Previous | Next >