Created
June 12, 2017 17:27
-
-
Save brentschooley/a9933d4a790ecfd2268b030782052b65 to your computer and use it in GitHub Desktop.
Twilio Function for retrieving cat gifs from The Cat API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.handler = function(context, event, callback) { | |
var client = context.getTwilioClient(); | |
console.log("Sending initial response") | |
client.messages.create({ | |
to: event.From, | |
from: event.To, | |
body: "Fetching a cat for you, one sec..." | |
}, function(err, res) { | |
console.log("Sending a cat!") | |
let twiml = new Twilio.twiml.MessagingResponse(); | |
let message = twiml.message(); | |
message.body("Here's your cat!"); | |
message.media("http://thecatapi.com/api/images/get?format=src&type=gif") | |
callback(null, twiml); | |
}) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi i would like to write a twilio function wich send a response base on the incoming message.
lets say, if i send an sms wich says "aaa"
the twiml message will be "answer to aaa"
if i send "bbb"
the twiml message will be 'answer to bbb"
and if i send something else
the twiml message will be "please say aaa or bbb"
i am actually using this function
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.MessagingResponse();
twiml.message("hello you just send a message to your twilio number");
callback(null, twiml);
};
but it will answer this message whatever the input is...
i would like the function to know what is the incoming message body...
can you help me please ?