メニュー

Expand
ページを評価:

Custom Channel V1 [Deprecated]

With Twilio Autopilot, you can build your own channel integrations to integrate your custom-built chat or existing messaging platforms that we don't support natively. In this guide, we will walk you through sending a message to the custom channel endpoint and the structure of the Autopilot response so you can build a bot on any channel.

When should I use a custom channel?

You should use a custom channel when you want to build a bot on a channel that Autopilot does not support natively. For example, if you want to build a bot on your custom-built webchat or a platform like Intercom, Front or Discord.

メッセージの送信

When a user sends a message to the bot, you need to receive that message and send it to the custom channel endpoint.

Custom Endpoint

To send a message to Autopilot, you need to make an HTTP POST request to the custom endpoint you can find below:

https://channels.autopilot.twilio.com/v1/{AccountSid}/{AssistantSid}/custom/{YouCustomChannelName}

Replace the following in the url:

{AccountSid} = You Account Sid found in Console->Autopilot->Your Assistant ->Overview ->Properties

{AssistantSid} = You Autopilot Assistant Sid found in Console->Autopilot->Your Assistant ->Overview ->Properties

{YourCustomChannelName} = The name of your custom channel (For example: "webchat" or "discord")

パラメーター

The Custom Channel endpoint takes the following parameters:

パラメーター 概要
テキスト The user's text input.
user_id A user identifier. It can be any string that identifies the user.

認証

Your POST request must be authenticated using your AccountSid and token like any other Twilio API request.

The Response

When you send a message to the custom endpoint you will get a JSON back with the content to display back to the user.

{
  "shows": [],
  "says": [
    {
      "speech": "Welcome to Deep Table, The world's smartest restaurant. I'm Deep Table's virtual Assistant. I can help you make reservations or tell you about today's special. What would you like to do?"
    }
  ],
  "listen": {}
}

Your channel integration should take this content and render it back to the user.

Autopilot will still do all the dialogue and state management for Actions like Collect. It will just respond with one message at a time.

Autopilot URL Parameters

パラメーター 概要
TargetTask

A string representing the unique name of the destination Task. If no TargetTask is provided, the destination task is determined by the natural language understanding.


TargetTask is useful when you want to control what task a user is routed to.

Memory

Lets you send Inbound Context to Autopilot. Should be a JSON string containing key-value pairs to insert into the Autopilot memory before starting a dialogue with the bot.

Useful for passing data stored in third party systems like a CRM into Autopilot to deliver a more contextual experience.

For Example: Note the TargetTask parameter at the end of the URL

https://channels.autopilot.twilio.com/v1/<ACCOUNT_SID>/<ASSISTANT_SID>/custom/{YouCustomChannelName}?TargetTask=handle_appointment_confirmation

Any message sent to number or messaging service configured with this URL will land in the handle_appointment_confirmation task.

Example 2: Passing Inbound Context with Memory

https://channels.autopilot.twilio.com/v1/<ACCOUNT_SID>/<ASSISTANT_SID>/custom/{YourCustomChannelName}?Memory={"CarModel":"Diablo","CarMake":"Lamborghini","CarYear":"2019"}

Any message sent to a bot with this URL will insert CarModel, CarMake and CarYear into the Autopilot Memory.

Example Function

- Make sure you enable ACCOUNT_SID and AUTH_TOKEN in the Functions -> Configure.

Screen Shot 2019-07-30 at 1.06.19 PM.png

- Replace {AssistantSid} with your Assistant Sid.

var got = require('got');

exports.handler = function(context, event, callback) {
    
    // Takes the first message, creates the channel webhook
    console.log(event);
    
    // Pipe body to Autopilot
    let requestPayload = "user_id=nico&text=Monis"

    got.post('https://channels.autopilot.twilio.com/v1/'+context.ACCOUNT_SID+'/{AssistantSid}/custom/UberEatsBot', 
    { 
        headers: { 
            'content-type': 'application/x-www-form-urlencoded',
            'accept': 'application/json',
            'authorization' :  'Basic ' + new Buffer(context.ACCOUNT_SID+ ':' + context.AUTH_TOKEN).toString('base64')
        },
        body: requestPayload
    }).then(function(response) {
        let apResponse = JSON.parse(response.body);
        console.log(apResponse);
        callback();
        
    }).catch(function(error) {
        callback(error)
    });
  
};
ページを評価:

ヘルプが必要ですか?

誰しもが一度は考える「コーディングって難しい」。そんな時は、お問い合わせフォームから質問してください。 または、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