Twilio Autopilot's custom channel Memory payload

42
November 25, 2021, at 05:30 AM

I'm creating a web chat and I need to integrate an assistant using Twilio Autopilot, I use Autopilot's custom channels as follows:

  • I send a POST request to https://channels.autopilot.twilio.com/v2/{AccountSid}/{AssistantSid}/custom/webchat
  • I fill in these fields in the request data (Language=en-US, UserId=user123, Text=Something)
  • I add a Memory parameter in the Assistant URL

My backend code:

    // Assistant URL Memory parameter
    const context = JSON.stringify({
        accountHolder: "foo bar",
        balance: 123
    }, null, "");
    // Request params
    const urlencoded = new URLSearchParams();
    urlencoded.append("Language", "en-US");
    urlencoded.append("UserId", message.Author);
    urlencoded.append("Text", message.Body);
    const requestConfig: AxiosRequestConfig = {
        headers: {
            "content-type": "application/x-www-form-urlencoded",
            "accept": "application/json",
            "authorization" :  "Basic " + Buffer.from(accountSid + ":" + authToken).toString("base64")
        },
        method: "POST",
        url: `https://channels.autopilot.twilio.com/v2/${accountSid}/${assistantSid}/custom/webchat?Memory=${context}`,
        data: urlencoded
    };
    // Trigger the bot
    const twilioResponse = this.httpService.request(requestConfig);
    const result = await lastValueFrom(twilioResponse.pipe(map((response) => response.data)));

Twilio function:

exports.handler = async function(context, event, callback) {
  console.log(event.Memory);
  const userData = JSON.parse(event.Memory); // Memory does not contains my payload !
  return callback(null, {
    "actions": [
      {
        "say": `Hello ${userData.accountHolder}, your balance is ${userData.balance}`
      },
      {
        "listen": true
      }
    ]
  });
};

My problem is, The Memory parameter is not sent to the function

READ ALSO
"Requiring Wifi permissions limits app availability on TVs that support only Ethernet" warning in Android Studio - can anything be done about this?

"Requiring Wifi permissions limits app availability on TVs that support only Ethernet" warning in Android Studio - can anything be done about this?

I'm developing an Android app (a game) that supports phones and TVs too, and can play multiplayer via LAN (WiFi or Ethernet) or WiFi Direct

71
Trying to pull from a folder of images

Trying to pull from a folder of images

Hi first time here and I'm very new to coding

9
Python is not able to read the file

Python is not able to read the file

Let me rephrase the questionThe equal signs are in the code, i hope that this is showed in the following lines of code

41