Skip to content

Instantly share code, notes, and snippets.

@jcipriano
Created May 9, 2017 23:24
Show Gist options
  • Save jcipriano/5254e20dcd2fc440facfe9add22358c4 to your computer and use it in GitHub Desktop.
Save jcipriano/5254e20dcd2fc440facfe9add22358c4 to your computer and use it in GitHub Desktop.
var nconf = require('nconf')
var request = require('request')
// load config
nconf.file({ file: 'config.json' }).env()
// twitter authentication
var twitter_oauth = {
consumer_key: nconf.get('TWITTER_CONSUMER_KEY'),
consumer_secret: nconf.get('TWITTER_CONSUMER_SECRET'),
token: nconf.get('TWITTER_ACCESS_TOKEN'),
token_secret: nconf.get('TWITTER_ACCESS_TOKEN_SECRET')
}
// direct message request body
var dm_params = {
"event": {
"type": "message_create",
"message_create": {
"target": {
"recipient_id": "4534871",
},
"message_data": {
"text": "I’m sorry your burrito is bad. Which location did you order from?",
"quick_reply": {
"type": "location",
"location": {
"metadata": "external_id"
}
}
}
}
}
}
// request options
var request_options = {
url: 'https://api.twitter.com/1.1/direct_messages/events/new.json',
oauth: twitter_oauth,
json: true,
headers: {
'content-type': 'application/json'
},
body: dm_params
}
// POST request to send Direct Message
request.post(request_options, function (error, response, body) {
console.log(body)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment