Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dudanogueira/46c6ab94007376597c9660c6f0a293ac to your computer and use it in GitHub Desktop.
Save dudanogueira/46c6ab94007376597c9660c6f0a293ac to your computer and use it in GitHub Desktop.
Rocket.Chat Twillio integration for outgoing sms
/* exported Script */
/* globals console, _, s, HTTP */
// Author: [email protected]
/** Global Helpers
*
* console - A normal console instance
* _ - An underscore instance
* s - An underscore string instance
* HTTP - The Meteor HTTP object to do sync http calls
*/
class Script {
/**
* @params {object} request
*/
prepare_outgoing_request({ request }) {
// request.params {object}
// request.method {string}
// request.url {string}
// request.auth {string}
// request.headers {object}
// request.data.token {string}
// request.data.channel_id {string}
// request.data.channel_name {string}
// request.data.timestamp {date}
// request.data.user_id {string}
// request.data.user_name {string}
// request.data.text {string}
// request.data.trigger_word {string}
body = request.data.text.split(" ").slice(2).join(" ");
to = request.data.text.split(" ")[1];
var dataString = 'From=+15017122661&Body=' + body + '&To=' + to;
//headers = request.headers["Content-Type"] = "application/json";
return {
url: request.url + '?' + dataString,
method: 'POST',
headers: request.headers,
body: dataString,
data: {
To: to,
Body: body
},
auth: "UUUUUSER:PASSWD",
};
}
/**
* @params {object} request, response
*/
process_outgoing_response({ request, response }) {
return {
content: {
text: "RESPONSE: " + response.content,
parseUrls: false
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment