Last active
December 15, 2017 16:48
-
-
Save mheap/0073f66d40a7f3085fa381500c303226 to your computer and use it in GitHub Desktop.
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
// Sign up for nexmo.com | |
// Purchase a number | |
// Set the webhook URL for inbound messages (https://dashboard.nexmo.com/settings) to be yourdomain.com:3000/webhooks/sms-inbound | |
// Fill in the Twitter credentials below (you'll need to register an application at https://apps.twitter.com) | |
// Run this code | |
// Send STOP to the number you created | |
// Watch as @rosstuck gets a tweet asking him to stop | |
const app = require('express')() | |
const bodyParser = require('body-parser') | |
const Twitter = require('twitter'); | |
var client = new Twitter({ | |
consumer_key: '', | |
consumer_secret: '', | |
access_token_key: '', | |
access_token_secret: '' | |
}); | |
app.use(bodyParser.json()) | |
app.use(bodyParser.urlencoded({ extended: true })) | |
app | |
.route('/webhooks/inbound-sms') | |
.get(handleInboundSms) | |
.post(handleInboundSms) | |
function handleInboundSms(request, response) { | |
const params = Object.assign(request.query, request.body) | |
console.log(params) | |
if (params.text == 'STOP') { | |
client.post('statuses/update', {status: '@rosstuck STOP! Please... stop...'}, function(error, tweet) { | |
if(error) throw error; | |
console.log(tweet); | |
}); | |
} | |
response.status(204).send() | |
} | |
app.listen(3000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment