WebChat

This guide provides detailed instructions on implementing a chatbot using the Microsoft Bot Framework WebChat JavaScript library. The implementation involves obtaining a token from a backend service a

Implementation Steps

Step 1: Obtain the Bot User Token (TBD)

Use the following endpoint to obtain the bot user token: {host_url}/partner/xpbot/api/webchat/initForClient

To ensure that the backend correctly transmits the information required by the client to initialize the token using the API endpoint provided by XBot. To handle token expiration and refresh the token for the client, you can implement a mechanism that checks the token's expiration time and automatically refreshes it before it expires

Example function to get the token:

import axios from 'axios';

export enum BOT_CODE_ENUM {
    ISIGN = 'ISIGN_WEBCHAT'
}

const getBotToken = async () => {
  try {
    const response = await axios.post('https://initForClient', { 
      botCode: 'YOUR_BOT_CODE' // Defined by Backend, eg: BOT_CODE_ENUM.ISIGN
    });

    return response.data.token;
  } catch (error) {
    console.error('Error fetching bot token:', error);
  }

Step 2: Initialize the Chatbot

Create a function to initialize the chatbot using the Microsoft Bot Framework WebChat SDK:

Step 3: Integrate the Chatbot into Your Application

React Example

Angular Example

Customization

You can customize the appearance and behavior of the Web Chat control using the styleOptions property. For example, you can change the avatars, colors, and typing indicators.

Example of Custom Style Options:

Additional Resources

For more detailed information and examples, refer to the following resources:

Last updated