Send an event

Updated 

sprChat('sendExternalEvent')

This API can be used to publish a message or an event in an ongoing open conversation.

An event is a special kind of message that Sprinklr bot understands and responds to. It is like a signal to the bot only and is not visible to the user in the conversation.

Parameters:

(every parameter is optional unless marked *):

Name

Typescript type

Description

Required

clientExternalEvent

MessagePublishExternalEvent | EventPublishClientExternalEvent




type MessagePublishExternalEvent = {

      type: 'MSG_PUBLISH';

      payload: {
        //conversation id to publish the message in. If not specified, the latest, active and open conversation is used

        //

        contextId?: string; 

        //

        // unique identifier that you can can send and expect back in updates on publish success/failure of this event

        id: string;

        //

        message: Message;


        // should send on behalf of brand or user 

        //

        isSentByUser?: boolean;

        //map of custom field ids vs their value that should be updated on the conversation 

        //

        messageContext?: StringTMap<string[]>;

      };

}



type EventPublishClientExternalEvent = {

  type: 'EVENT_PUBLISH';

  payload: {

    //conversation id to publish the message in. If not specified, the latest, active and open conversation is used

    //

    contextId: string;

    //

    // unique identifier that you can can send and expect back in updates on publish success/failure of this event

    id: string;

    //

    event: {

      type: string;

      [key: string]: any;

    };

  };

}

Message or Event to publish

Yes


Examples 

Publishes a brand message, with the id of ‘123’ on the latest active and open conversation & passes the message context  ‘_m_asfd12’ with value ‘abc’ 

window.sprChat('sendExternalEvent', {
    type:
'MSG_PUBLISH',
    payload: {
        id:
'123',
        message: {
          text:
'Hello world',
        },
        messageContext: {
'_m_asfd12': [‘abc’],
        },
  },
});


Sends an event of type 'MY_CUSTOM_EVENT' to the bot on the latest active and open conversation. This event has already been defined by the creator in Sprinklr Bot.

window.sprChat('sendExternalEvent', {
    type:
'EVENT_PUBLISH',
    payload: {
        contextId:
'6347db4b6b441a7a1eed68b8',
        id:
'123',
        event: {
          type:
'MY_CUSTOM_EVENT',
        };
    };
});