Open the Widget programmatically, and enable the start button if it is disabled.
If the property autoShow is true, don't use this function after the function connect() that starts the rendering process of the component
widgetInstance.open();
case scenarios:
At the creation stage of the widget it is asked to open the widget automatically, then the property autoShow would be set to true. When the widget is created by the client, they want to have more control over the behavior of the widget and so it is created with the dynamic method, open it up to the use of the integrated methods, and they happen to want to use the open method after the connect() method.
Close Widget
Close Widget programmatically, with optional start button disable property.
/** * Close Widget * @param{boolean} disable property to deactivate (is optional) * @return{void} */widgetInstance.close(true);widgetInstance.close();
Enable Widget
Enable the Widget start button if it is disabled.
widgetInstance.enable()
Set Flow
someFlowId is the id number of a specific flow from the bot that is being used by the widget and someStringValue is the string value of the injected parameters.
/** * Get Members Array * @param{number} flowId Id of the room * @param{Record<string, string>?} storedParams object of params and values, is optional * @return{Promise<void>} */// without context widgetInstance.setFlow("<someFlowId>");// with contextwidgetInstance.setFlow("<someFlowId>", { param1:"<someStringValue>", param2:"<someStringValue2>",... paramN: "<someStringValueN>", });
/** * Get Members Array * @param{string} roomId Id of the room * @return{Promise<Member[]>} the list of members inside the room */widgetInstance.getMembers("<roomId>");// example// [// {// "id": "<some-id>",// "referenceId": "<some-reference-id>",// "roomId": "<some-room-id>",// "botId": "<some-bot-id>",// "companyId": "<numeric-company-id>",// "socketId": "<some-socket-id>",// "createdAt": "2022-01-14T21:47:24.556Z",// "memberType": "user"// },// {// "id": "<some-id>",// "legalId": "<some-legal-id>",// "names": "alexander",// "referenceId": "<some-reference-id>",// "roomId": "<some-room-id>",// "groupRoomId": "<some-group-room-id>",// "botId": "<some-bot-id>",// "companyId": "<numeric-company-id>",// "socketId": "<some-socket-id>",// "createdAt": "2022-01-14T21:47:24.000Z",// "memberType": "user"// },// {// "id": "<some-id>",// "legalId": "<some-legal-id>",// "names": "alexander",// "referenceId": "<some-reference-id>",// "roomId": "<some-room-id>",// "groupRoomId": "<some-group-room-id>",// "botId": "<some-bot-id>",// "companyId": "<numeric-company-id>",// "socketId": "<some-socket-id>",// "createdAt": "2021-12-17T22:59:38.000Z",// "memberType": "user"// }// ],
Set Current Room
/** * Set Current Room * @param{string} roomId Id of the room * @return{void} */widgetInstance.setCurrentRoom("<roomId>");
Join Room
/** * @typedefApiResponse * @property{string[]} message Response message * @property{boolean} status Response status boolean * @property{string} statusMessage Response status message *//** * Join Room * @param{string} roomId Id of the room * @param{string} userId Id of the user * @return{Promise<ApiResponse>} Promise response */widgetInstance.joinRoom("<roomId>","<userId>");
Leave Room
/** * @typedefApiResponse * @property{string[]} message Response message * @property{boolean} status Response status boolean * @property{string} statusMessage Response status message *//** * Leave Room * @param{string} roomId Id of the room * @param{string} userId Id of the user * @return{Promise<ApiResponse>} Promise response */widgetInstance.joinRoom("<roomId>");
Open Room With User
Open a chat with a specific user.
/**
* Open Room With User
* @param {string} userId Id of the user
* @return {Promise<void>} Promise response
*/
widgetInstance.openRoomWithUser({ id: <someId>, names: <someName> });
This method automatically opens the widget if it is closed.
Hide Home Menu
If you are in the home menu view this will hide it and show the chat view, in case you are already in chat view, it will do nothing.
/** * Hide Home Menu * @return{void} Promise response */widgetInstance.hideHomeMenu();
Show Home Menu
If you are in the chat view this will show the home menu view. In case the home menu view is already showing, it will do nothing.
/** * Show Home Menu * @return{void} Promise response */widgetInstance.showHomeMenu();
// disable the text input, plus button(document, image and location) and
// microphone button.
widgetInstance.disableInputs();
Enable Input Options
// enable the text input, plus button(document, image and location) and
// microphone button.
widgetInstance.enableInputs();
Add Member
Add a contact to an existing room.
/** * @typedefApiResponse * @property{string[]} message Response message * @property{boolean} status Response status boolean * @property{string} statusMessage Response status message *//** * Add member * @param{Contact} contact object * @param{string} roomId Id of the room * @return{Promise<ApiResponse | string>} Promise response */widgetInstance.addMember("<contact>","<roomId>");/** * Add member * @param{string} id Id of the user * @param{string} roomId Id of the room * @return{Promise<ApiResponse | string>} Promise response */widgetInstance.addMember("<id>","<roomId>");
Add Members
Add a list of contacts to an existing room.
/** * @typedefApiResponse * @property{string[]} message Response message * @property{boolean} status Response status boolean * @property{string} statusMessage Response status message *//** * Add members * @param{Contact} contact object * @param{string} roomId Id of the room * @return{Promise<ApiResponse | string>} Promise response */widgetInstance.addMembers("<roomId>", [ { referenceId:"<someId1>", names:"<someName1>", memberType:"Client"|"Operator"// Optional @default "Client" }, { referenceId:"<someId2>", names:"<someName2"> },..., { referenceId:"<someIdN>", names:"<someNameN"> } ]);
Get Messages
Returns the message history of a given room, in a defined number and counted from a certain message within that room.
The argument of the getMessages() function is an object with the following keys:
roomId: Is a mandatory key with a value of type “string”, that corresponds to the ID of the room from which messages will be fetched.
limit: Is an optional key with a value of type “number”, that corresponds to the number of messages to be fetched. If not set, the “getMessages” function will take the default value of 20, and therefore it will bring 20 messages.
id: Is an optional key with a value of type “string” or “number”, that corresponds to the message ID from which a number of messages determined by the "limit" parameter will be fetched. If not set, the “getMessages” function will take the default value of null, and therefore it will bring the last sent messages, according to the established “limit”.
The sendMessage() function is the that responsible for sending messages in Widget. You can send the following types of messages:
TextMessage
ImageMessage
AudioMessage
VideoMessage
DocumentMessage
LocationMessage
PostbackMessage
EventMessage
The message to be sent is an object that will have base keys, shared by all message types, and additional keys, which will depend on the type of message being sent.