メニュー

Installing and using Flex WebChat

Auto-Generated Documentation for the Flex Webchat UI is now available as a beta distribution. The auto-generated documentation is accurate and comprehensive but may differ from what you see in the official Flex Webchat UI documentation.

What is Flex WebChat?

Flex WebChat is a chat widget that you can embed on your website. The widget helps your customers chat with an agent without needing to leave your webpage. It is natively integrated with the Flex Contact Center.

What can you do with WebChat?

The Flex WebChat experience is fully customizable. WebChat can be customized in the following ways:

The following WebChat documentation applies to WebChat version 2.0.0 or higher. Please refer to the release notes to see what has changed since version 2.0.0.

Getting started with WebChat

There are currently two ways to consume Flex WebChat:

前提条件

To get access and set up Flex WebChat, you will need to complete the Flex Quickstart first.

Consuming from CDN

There are 2 ways to add Flex WebChat from CDN:

Option 1

The following steps are the quickest way to add Flex WebChat to your app. However, a CDN setup will not allow for more advanced programmability of the initialization flow for Flex WebChat.

1. Add the following script tag to the index.html head tag to include WebChat bundle from CDN.

You can optionally include an integrity token to verify that Flex WebChat is delivered without unexpected manipulation. If so, make sure to include "integrity" and "crossorigin" keys in the script.

<script src="https://assets.flex.twilio.com/releases/flex-webchat-ui/2.6.0/twilio-flex-webchat.min.js" integrity="sha512-E1OX3Cyq3KaDo4WM6fITGRv2eiGQbK40AJxNdsvC6BRxkUGp7f4RchZeOAVXHTTA3+4KjSeZDJB1cFpikR5EVw==" crossorigin></script>

The following table displays the integrity tokens of previous versions (starting from v2.2.0).

バージョン Integrity Token
2.6.0 sha512-E1OX3Cyq3KaDo4WM6fITGRv2eiGQbK40AJxNdsvC6BRxkUGp7f4RchZeOAVXHTTA3+4KjSeZDJB1cFpikR5EVw==
2.5.1 sha512-PtzV20UxBmoawZw6NrwzeHTrGYUBTVOe2dRO1PFnhilM48HKgbQ6BId5QURWoK3d3Fjgw03h8xTl3YvBvqzIuQ==
2.5.0 sha512-aJbAHiYQxwqK+Hi32EnFKywUXDp8bPtKNwm/pSgd5Eie7OW28RQlKxmKqvDhiekVRD0reJNSbzF5wjK4VG85sQ==
2.4.0 sha512-sJe2ZYbixQ0qDkEDC0c0DWjEAo6a5+fwPjCVQ4uWAj89hnFsYZgwbG/AFWlbNzFKkue7lM5oWqXjMp7p6Fi0KQ==
2.3.1 sha512-v+iq1pWN5HHQtNoUKDnQCVJhTgmbozCgRKkIdCI4Ub8bKuXs7TmPDoEAtPZJXExY+0CNw4vU+TlosD6MEvNn+g==
2.3.0 sha512-G4oFESS6nt1URwN23X670e1N7UIgiGJyINEsyrexNp28GSSrJ6GVwJCDElIDaZUIHOJiEwoJPdi2iT5S03XzKw==
2.2.1 sha512-q5oRRUPjLeW69a3nlGBt0iR4V5yBY/7ALQ85veEPFRh1xfp8LPy6/JwITfHJVqfNnDOqXpvnyiijNGWYlK8dSw==
2.2.0 sha512-bOmqok+FZdtlOKVEy830tV9tNvTm7dknDYWwZLcB/O4q3Cg5oS7jDoZO4zzHL2nAjlc5Im4Ws+4RZNemvetSHA==

2. Add the following script tag to the index.html body tag to initialize WebChat.

          <script>
            const appConfig = {
                accountSid:"AC...",
                flexFlowSid:"FO..."
            };
            Twilio.FlexWebChat.renderWebChat(appConfig);
        </script>

Option 2

The following steps will allow you to customize the FlexWebChat initialization flow before you render the WebChat, as it consists of two parts: initialize and render. This option allows you to tap into customization before the render method executes.

Twilio.FlexWebChat.createWebChat(appConfig).then(webchat => {
    const { manager } = webchat;
    
//Posting question from preengagement form as users first chat message
    Twilio.FlexWebChat.Actions.on("afterStartEngagement", (payload) => {
        const { question } = payload.formData;
        if (!question)
            return;

        const { channelSid } = manager.store.getState().flex.session;
        manager
            .chatClient.getChannelBySid(channelSid)
            .then(channel => channel.sendMessage(question));
    });
// Changing the Welcome message
    manager.strings.WelcomeMessage = "New text for welcome message";

// Render WebChat
    webchat.init();
  });

While logged into Flex as an administrator, you can find the flexFlowSid and accountSid in the Flex admin (https://flex.twilio.com/admin/developers). You can learn more about Projects in the Twilio Support Documentation.

Consuming from NPM and running locally

To get you started with consuming the @twilio/flex-webchat-ui package from npm, we provide a sample project based on create-react-app.

Run the following steps to get started using the sample project:

1. Clone the sample project from GitHub.

$ git clone https://github.com/twilio/flex-webchat-ui-sample.git

2. Change into the flex-webchat-ui-sample directory, then install dependencies.

cd flex-webchat-ui-sample
npm install

3. Copy the sample configuration and edit webchat-appConfig.js accordingly to your Twilio account.

cp public/assets/webchat-appConfig.sample.js public/assets/webchat-appConfig.js

4. Start the test server.

npm start

5. Your local Flex UI will be running on http://localhost:8081.

WebChat default behavior

WebChat

Out of the box, the WebChat is configured to initiate chat (trigger startEngagement action) on user entryPoint click. The following steps happen on start of the engagement:

  • Token is issued
  • Chat channel is created
  • Programmable chat user is created with default friendlyName and added as a member to the channel
  • MessagingCanvas is loaded with the created channelSid
  • A predefined message is shown to the user as a call to action.

WebChat is one of the channels that is integrated with Flex out of the box. When an incoming message is sent to the chat channel, it triggers a Studio Flow. By default, this is the Webchat Flow, which you can customize within the Twilio Console.

The first incoming message on the chat channel will trigger a new execution on the Studio Flow. Here you can automate a conversation using the Send & Wait for Reply widget before passing the conversation directly to an agent with the Send to Flex widget.

The Send to Flex widget then creates a TaskRouter task with the attributes provided, and removes the chat channel webhook so that future incoming messages won't retrigger the Studio flow.

Pre-engagement data can be accessed by Studio's Liquid syntax. For example, you could include in the Send to Flex widget:

{"question": "{{trigger.message.ChannelAttributes.pre_engagement_data.question}}"}

関連トピック

Now that you are all set up and got WebChat running, you can:

and much more!

ページを評価:

ヘルプが必要ですか?

誰しもが一度は考える「コーディングって難しい」。そんな時は、お問い合わせフォームから質問してください。 または、Stack Overflow でTwilioタグのついた情報から欲しいものを探してみましょう。

フィードバックくださりありがとうございます!

We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

Sending your feedback...
🎉 Thank you for your feedback!
Something went wrong. Please try again.

Thanks for your feedback!

Refer us and get $10 in 3 simple steps!

ステップ1

Get link

Get a free personal referral link here

ステップ2:

Give $10

Your user signs up and upgrade using link

ステップ3

Get $10

1,250 free SMSes
OR 1,000 free voice mins
OR 12,000 chats
OR more