Skip to content

Instantly share code, notes, and snippets.

@spasiu
spasiu / adding_metadata.js
Created June 7, 2017 21:09
adding metadata
/*
Smooch's POST message endpoint accepts a flat JSON property called metadata.
It provides developers with the opportunity to pass additional information with the message.
By default, the metadata property is not rendered in Smooch's messaging channels.
See https://docs.smooch.io/rest/#post-message for more information.
Here we'll show an example of using message metadata with the intention of passing a link to a video along with a message.
A developer may then extend a client, like Smooch's Web or native mobile SDKs, to render the video in the chat.
We will not cover the rendering of the video here.
*/
@spasiu
spasiu / request_to_link.js
Created June 7, 2017 20:47
Sending a request to message that links the appUser to a new channel
@spasiu
spasiu / create_twitter_integration.js
Created May 12, 2017 14:34
Integrate with Twitter using Smooch core
const Smooch = require('smooch-core');
const ACCOUNT_KEY_ID = 'your_smooch_account_key_id';
const ACCOUNT_SECRET = 'your_smooch_account_secret';
const APP_ID = 'your_smooch_app_id';
const CONSUMER_KEY = 'your_twitter_consumer_key';
const CONSUMER_SECRET = 'your_twitter_consumer_secret';
const ACCESS_TOKEN_KEY = 'your_twitter_access_token';
const ACCESS_TOKEN_SECRET = 'your_twitter_access_token_secret';
@spasiu
spasiu / ott-channels.md
Created April 13, 2017 19:13
how to connect a smooch user to another channel

Telegram: https://telegram.me/{TELEGRAM_BOT_NAME}?start={SMOOCH_APPUSER_ID}

Viber: viber://pa?chatURI={VIBER_URI}&context={SMOOCH_APPUSER_ID}

Messenger: http://m.me/{FB_PAGE_ID}?ref={SMOOCH_APPUSER_ID}

@spasiu
spasiu / index.js
Last active April 27, 2017 03:50
send custom notes to zendesk from smooch events
const qs = require('qs');
const express = require('express');
const bodyParser = require('body-parser');
const superagent = require('superagent');
const AUTHOR_ID = ''; // Zendesk user id for the user who will post notes, e.g. "517393059"
const USERNAME = ''; // username for the Zendesk user who authorizes API access, e.g "stasi@smooch.io"
const PASSWORD = ''; // password for the Zendesk user who authorizes API access, e.g. "princess"
const SUBDOMAIN = ''; // Zendesk subdomain, e.g. "stasicorp"
@spasiu
spasiu / integrate-shortcode.js
Created March 16, 2017 18:11
Integrate a Twilio shortcode to Smooch
const twilioAccountSid = '';
const twilioAuthToken = '';
const twilioPhonenumberSid = '';
const smoochAccountKeyId = '';
const smoochAccountSecret = '';
const smoochAppId = '';
const Smooch = require('smooch-core');
const smooch = new Smooch({
@spasiu
spasiu / app.js
Created March 16, 2017 01:49
real time app with polling example for JS101
const catPut = document.getElementById('cat-input');
const catList = document.getElementById('cat-list');
document.getElementById('cat-button').onclick = () => {
const cat = catPut.value;
superagent.post('/cats').send({ cat }).end((err, res) => {
err ? alert(err.message) : catPut.value = '';
});
}
@spasiu
spasiu / smooch-account-jwt.js
Created March 10, 2017 17:58
Get account scope jwt
const authToken = require('jsonwebtoken').sign({ scope: 'account' }, 'your_secret_key', {
header: {
typ: 'JWT',
kid: 'your_key_id',
alg: 'HS256'
}
});
@spasiu
spasiu / markdown-file-splitter.js
Created March 9, 2017 20:42
Script to split Markdown files
const fs = require('fs');
const PATH = process.argv[2] || __dirname;
const LEVEL = parseInt(process.argv[3] || 1);
const TARGET = process.argv[4];
const DELETE = process.argv[5];
fs.readdirSync(PATH)
.filter(isOptionalTarget)
.filter(isMarkdownFile)
@spasiu
spasiu / qs.py
Created March 8, 2017 04:10
Quicksort in python
def qs(compare, items):
if len(items) < 2: return items
pivot = items[0]
left = []
right = []
for item in items[1:]:
if compare(pivot, item): left.append(item)
else: right.append(item)