Skip to content

Instantly share code, notes, and snippets.

@spasiu
Last active May 18, 2016 02:36
Show Gist options
  • Select an option

  • Save spasiu/3a0c19a4a674ee418659d3b95846cb36 to your computer and use it in GitHub Desktop.

Select an option

Save spasiu/3a0c19a4a674ee418659d3b95846cb36 to your computer and use it in GitHub Desktop.
post a message to Smooch with Ruby
require 'unirest'
require 'jwt'
SECRET = 'your_secret'
KEY_ID = 'your_key'
USER_ID = 'user_id'
payload = {
:scope => 'app'
}
headers = {
:alg => 'HS256',
:kid => KEY_ID
}
token = JWT.encode payload, SECRET, 'HS256', headers
response = Unirest.post "https://app.smooch.io/v1/appusers/#{USER_ID}/conversation/messages",
headers: {
"Accept" => "application/json",
"Content-Type" => "application/json",
"Authorization" => "Bearer #{token}"
},
parameters:{
:text => "Hello",
:role => "appMaker"
}
puts "#{response.code}\n\n#{response.body}\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment