Menu

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?

Tell a random joke

To create a function that tells a random joke that you can leverage in your Autopilot experience, you can use a function to call the icanhazdadjoke api which returns a random joke.

const axios = require('axios');

exports.handler = function(context, event, callback) {
    
    axios.get('https://icanhazdadjoke.com/', {
        headers: {
            Accept: 'text/plain'
        }
    }).then(function(response){
        console.log(response.data);
        let result = {
            "actions": [
                { 
                    "say": response.data 
                },
                {
                    "listen": true
                }
            ]
        };
        callback(null, result);
    });
};

Don't forget to add the axios dependency here.

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.