Skip to content

Instantly share code, notes, and snippets.

@spasiu
Last active November 25, 2016 19:00
Show Gist options
  • Select an option

  • Save spasiu/8ae55ea452378c2b87566ef48a58f095 to your computer and use it in GitHub Desktop.

Select an option

Save spasiu/8ae55ea452378c2b87566ef48a58f095 to your computer and use it in GitHub Desktop.
post message as appmaker
'use strict';
const jwt = require('jsonwebtoken');
const superagent = require('superagent');
const USER_ID = 'your_user_id';
const KEY_ID = 'your_key_id';
const SECRET = 'your_secret_key';
// Generate JWT
const authToken = jwt.sign({ scope: 'app' }, SECRET, {
header: {
typ: 'JWT',
kid: KEY_ID,
alg: 'HS256'
}
});
// POST Message
superagent
.post(`https://app.smooch.io/v1/appusers/${USER_ID}/conversation/messages`)
.send({
text: 'Live long and prosper',
role: 'appMaker'
})
.set('authorization', 'Bearer ' + authToken)
.set('Accept', 'application/json')
.end(function(err, response) {
console.log('API RESPONSE:\n', err, response.body, response.statusCode);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment