Skip to content

Instantly share code, notes, and snippets.

@spasiu
spasiu / email_capture.html
Created November 17, 2016 20:45
how to enable email capture with Smooch
<script src="https://cdn.smooch.io/smooch.min.js"></script>
<script>
Smooch.init({
appToken: 'your_app_token',
emailCaptureEnabled: true
});
</script>
@spasiu
spasiu / generate_jwt.js
Last active May 9, 2018 08:56
Generate an appmaker JWT for Smooch
'use strict';
const jwt = require('jsonwebtoken');
const KEY_ID = 'your_key_id';
const SECRET = 'your_secret';
const body = { scope: 'app' };
const config = {
header: {
typ: 'JWT',
kid: KEY_ID,
@spasiu
spasiu / body_logger.js
Last active October 31, 2016 13:21
Quick server to log pretty JSON bodies
'use strict';
const PORT = 8000;
const express = require('express');
const parseJsonBody = require('body-parser').json();
const logRequestBody = (req, res) => {
const prettyBody = JSON.stringify(req.body, null, 4);
console.log(prettyBody);
@spasiu
spasiu / postMessage.js
Last active November 25, 2016 19:00
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
@spasiu
spasiu / archive_smooch_slack.js
Last active May 20, 2016 23:55
rate-limited bulk archiving of smooch channels on Slack
'use strict';
const request = require('request')
const token = 'your_token'
const paths = {
list: `https://slack.com/api/channels.list?token=${token}&exclude_archived=1`,
archive: `https://slack.com/api/channels.archive?token=${token}&channel=`
}
const listChannels = () => new Promise(function(resolve, reject) {
request.get(paths.list, function(err, res, body) {
@spasiu
spasiu / smooch_webhooks.py
Created May 19, 2016 18:39
example of setting a webhook via the Smooch API in Python
import jwt # https://github.com/jpadilla/pyjwt
import requests # http://docs.python-requests.org/en/master/
SECRET = 'your_secret'
KID = 'your_key'
token = jwt.encode({'scope': 'app'}, SECRET, algorithm='HS256', headers={'kid': KID, 'alg': 'HS256'})
response = requests.get(url="https://app.smooch.io/v1/webhooks",
headers={'content-type': 'application/json', 'authorization': 'Bearer ' + token },
@spasiu
spasiu / post_message_smooch.rb
Last active May 18, 2016 02:36
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'
}
@spasiu
spasiu / jwt-server.js
Created April 18, 2016 22:10
server that generates JWTs with app scope to access the REST API Smooch
var jwt = require('jsonwebtoken');
var express = require('express');
var app = express();
var port = process.env.PORT || 3000;
app.get('/', function(req, res) {
var token = jwt.sign({
scope: 'app'
},
req.query.secret,
@spasiu
spasiu / post_image.js
Created April 5, 2016 01:43
upload image to smooch via rest api
var Smooch = require('smooch-core');
var request = require('request');
var jwt = require('jsonwebtoken');
var fs = require('fs');
var USER_ID = 'a_user_id';
var KEY_ID = 'your_key_id';
var SECRET = 'your_secret';
var token = jwt.sign({
scope: 'app'
},
@spasiu
spasiu / app_static.js
Created March 24, 2016 16:03
static files express
'use strict';
var express = require('express');
var app = express();
app.use('/public', express.static(__dirname + '/build'));
app.get('/', function(req, res) {
res.sendFile(__dirname + '/index.html');