Menu

Expand
Rate this page:

Thanks for rating this page!

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

Say

The Say action instructs an Assistant on what to speak back to the user. Say may contain SSML or plain text.

Example 1: Simple Say: Hello World!

{
	"actions": [
		{
			"say": "Hello World!"
		}
	]
}

This Say action would say "Hello World!" and end the dialogue. This is an example of statically-rendered JSON and the Say action is a static Action.

Example 2: Dynamic example: Say "Hello World" by calling dynamic JSON from a Twilio Function (or another endpoint) instead of the Autopilot Actions bin.

First you'll redirect to the Function from the Actions bin:

{
    "actions": [
        {
            "redirect": "replace-with-your-function.twil.io/dynamicsay"
        }
    ]
}

In the Twilio Function, your Node.js code to say "Hello World" by rendering Actions' JSON dynamically could look like this. This is also where you could add data from the conversation context, like the name of the user, to your bot's response:

exports.handler = function(context, event, callback) {
    let actions = [];
    let say = {
        "say": "Hello World!"
    }
    actions.push(say);
    let respObj = {
    	"actions": actions
    };
    callback(null, respObj);	
};

Example 3: Say with SSML

Speech Synthesis Markup Language (SSML) is a W3C specification that allows developers to use XML-based markup language for assisting the generation of synthesized speech. SSML will only work with Polly voices.

{
	"actions": [
		{
			"say": "John’s phone number is, <say-as interpret-as="telephone">4155551212</say-as>, would you like to call him?"
		},
		{
			"listen": true
		}
	]
}

You can find all the SSML documentation here.

Example 4: Channel Specific Responses

You can customize your bot's response for the different channels by generating dynamic JSON from a Twilio Function (or another backend). The example below responds a different message to users that interact with the Bot via voice, chat or any other channel.

exports.handler = function(context, event, callback) {
    let actions = [];
    let channel = event.Channel;
    let say = {};
    if (channel == 'voice'){
        say = {
        "say": "Welcome to the demo IVR!"
        }
    } else if (channel == 'chat') {
        say = {
        "say": "Welcome to the demo Chatbot!"
        }
    } else {
        say = {
        "say": "Welcome!"
        }
    }
    
    actions.push(say);
    let respObj = {
    	"actions": actions
    };
    callback(null, respObj);	
};
Rate this page:

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.