Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / beginner_smooch.md
Created November 23, 2016 17:43
how to start with Smooch and NodeJS

API Quick Start

Introduction

This quickstart will teach you to use Smooch's REST API, a Web messenger widget on a Website, and and some server-side code to create an auto response for when people send your business messages.

Prerequisites

You should be able to follow along in node.js, or another programming language; you should also have ngrok (which creates secure tunnels to localhost), or be otherwise able to deploy a server; and you should have already signed up for a Smooch account.

Setting up a Web server

First we'll set up a Web server:

@spasiu
spasiu / smooch_server.js
Last active November 29, 2016 22:18
A server for receiving user messages from Smooch and responding via the REST API.
'use strict';
// Imports
const express = require('express');
const bodyParser = require('body-parser');
const jwt = require('jsonwebtoken');
const superagent = require('superagent');
// Config
const PORT = process.env.PORT || 8000;
@spasiu
spasiu / smooch_webhook_payload.json
Created November 25, 2016 20:06
Sample Smooch Webhook payload with Facebook as a client
{
"trigger": "message:appUser",
"app": {
"_id": "58384af1c88e9558007a6a91"
},
"messages": [
{
"authorId": "2f1c2db75a79a99116ac99d3",
"received": 1480104343.829,
"text": "hey",
@spasiu
spasiu / hash.js
Created December 5, 2016 19:17
command line tool to generate hash from string
process.stdout.write(require('crypto').createHash('md5').update(process.argv[2]).digest("hex"));