Last active
May 18, 2016 02:36
-
-
Save spasiu/3a0c19a4a674ee418659d3b95846cb36 to your computer and use it in GitHub Desktop.
post a message to Smooch with Ruby
This file contains hidden or 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
| 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