Created
August 4, 2019 01:01
-
-
Save joeydotdev/6dc3fbb60aebedddba44be125bd98861 to your computer and use it in GitHub Desktop.
woofbot.io API & Twilio Integration
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
const axios = require('axios'); | |
exports.handler = function(context, event, callback) { | |
let twiml = new Twilio.twiml.MessagingResponse(); | |
// Take in user input | |
let breed = event.Body.toLowerCase(); | |
axios | |
// Include the `breed` variable in our HTTP request. | |
// Note the change from ' to ` | |
.get(`https://api.woofbot.io/v1/breeds/${breed}/image`) | |
.then((response) => { | |
// The call to our API has succeeded. In this case, we are given an | |
// object called `response` to play around with. | |
twiml.message().media(response.data.response.url); | |
callback(null, twiml); | |
}) | |
.catch((error) => { | |
// Oh no! Something went wrong in our API call. | |
// We should examine our `error` object to figure out what went wrong. | |
// Post to our debug logs in Twilio. | |
callback(null, error); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment