Skip to content

Instantly share code, notes, and snippets.

@joeydotdev
Created August 4, 2019 01:01
Show Gist options
  • Save joeydotdev/6dc3fbb60aebedddba44be125bd98861 to your computer and use it in GitHub Desktop.
Save joeydotdev/6dc3fbb60aebedddba44be125bd98861 to your computer and use it in GitHub Desktop.
woofbot.io API & Twilio Integration
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