Skip to content

Instantly share code, notes, and snippets.

@spasiu
spasiu / link_parent.js
Created December 7, 2018 16:29
Open link buttons in the parent window
@spasiu
spasiu / unload.js
Last active December 1, 2018 14:16
Send synchronous message from smooch web sdk on unload
window.appId = 'SMOOCH_APP_ID';
window.jwt = undefined; // optionaly set an app user JWT for authenticated users
/**
* Send synchronous message.
* @param {object} message - The same message object expected by Smooch.sendMessage https://github.com/smooch/smooch-web#sendmessagemessage.
* @param {string} appId - The appId used to initialize the Smooch Web SDK.
* @param {string} [jwt] - The JSON Web Token used to authenticate the app user, if not anonymous.
*/
@spasiu
spasiu / index.html
Created June 7, 2018 12:09
figuring out when initialization has finished in embedded mode
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="no-display" style="display:none;"></div>
<script>
var APP_ID = 'your-app-id';
@spasiu
spasiu / get_token.php
Created February 26, 2018 21:32
generating a smooch app user token in PHP
<?php
// using composer
require 'vendor/autoload.php';
// using https://github.com/firebase/php-jwt
use \Firebase\JWT\JWT;
$SMOOCH_APP_KEY_ID = "<YOUR_SMOOCH_APP_KEY_ID>";
$SMOOCH_APP_KEY_SECRET = "<YOUR_SMOOCH_APP_KEY_SECRET>";
@spasiu
spasiu / index.html
Last active July 31, 2018 07:53
Modify the Smooch Web SDK by manipulating iframe DOM
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script type="text/css" id="iframe-stylesheet">
@spasiu
spasiu / curl_request
Created February 8, 2018 15:40
Smooch webhook as Curl request
curl -X POST \
<WEBHOOK_TARGET> \
-H 'x-api-key: <WEBHOOK_SECRET>' \
-H 'content-type: application/json' \
-H 'accept: application/json' \
-H 'connection: close' \
-d '{"trigger":"message:appUser","app":{"_id":"<APP_ID>"},"messages":[{"text":"hi","type":"text","role":"appUser","received":1518102294.706,"authorId":"<APP_USER_ID>","name":"Peaceful Swordfish","_id":"<MESSAGE_ID>","source":{"type":"web","id":"<CLIENT_ID>"}}],"appUser":{"_id":"<APP_USER_ID>","signedUpAt":"2018-02-08T15:04:54.214Z","conversationStarted":true,"credentialRequired":true,"clients":[{"lastSeen":"2018-02-08T15:04:54.706Z","platform":"web","id":"<CLIENT_ID>","info":{"currentTitle":"","currentUrl":"http://localhost:4000/","browserLanguage":"en-US","referrer":"","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36","URL":"localhost:4000","sdkVersion":"4.5.4"},"raw":{"currentTitle":"","currentUrl":"http://localhost:4000/","browserLanguage":"en-US","
@spasiu
spasiu / delete.js
Created December 4, 2017 14:58
JP's Smooch channel deletion script for Slack
var request = require('request');
var token = "";
var url = 'https://slack.com/api/channels.list?token=' + token + '';
var channels = [];
request(url, function(err, res, body) {
if (err) {
throw err;
}
console.log('LIST', res.statusCode);
channels = JSON.parse(body).channels
@spasiu
spasiu / error_code_enumeration.txt
Created November 2, 2017 13:54
Enumeration of errors that Smooch might provide via the REST API and webhooks
ERROR CODES PROVIDED IN DELIVERY FAILURE WEBHOOKS
bad_request
blocked
not_found
rate_limited
service_internal_error
service_unavailable
unauthorized
uncategorized_error

Configuring Smooch's WeChat integration to work with an access token proxy

Access Token URL

Smooch makes it possible to manage your WeChat access tokens through a third party. This allows Smooch and another service to make API calls to WeChat simultaneously without conflicts.

In order to configure third party access token endpoints, you must integrate WeChat to Smooch via the REST API. It is not currently possible to configure the required parameter through the UI.

The WeChat integration endpoint now accepts an optional property accessTokenUrl. Once this property is set, Smooch will call the new endpoint to generate access tokens.

See below for an example of an API call to configure WeChat with third party access token service:

@spasiu
spasiu / facebook_transfer_request.js
Created June 24, 2017 10:31
Initiate a Smooch transfer request for Facebook
const superagent = require('superagent');
const jwt = require('jsonwebtoken');
const APP_KEY_ID = process.env.SMOOCH_KEY_ID;
const APP_SECRET_KEY = process.env.SMOOCH_SECRET;
const FACEBOOK_PAGE_ID = process.env.FACEBOOK_PAGE_ID;
const token = jwt.sign({
scope: 'app'
}, APP_SECRET_KEY, {