Skip to content

Instantly share code, notes, and snippets.

@Giuliano84
Giuliano84 / sample notification.js
Created November 8, 2018 22:50
Sample notification HUB CRM
{
"id": "AWb1e8ihMzmB0aArKzGg",
"status": "NOTIFIED",
"timestamp": "2018-11-08T22:40:22Z",
"accountId": 9733,
"element": "hubspot",
"elementInstance": "120964",
"error": "",
"providerData": {
"contacts": [
@Giuliano84
Giuliano84 / onfact
Last active April 18, 2018 12:35
onfact
{
"Contact" {
"type":"customer",
"name":"{{G0IW.incoming.body.Name}}",
"city":"{{G0IW.incoming.body.Gemeente}}",
"phone":"{{G0IW.incoming.body.Telefoon}}",
"vat":"{{G0IW.incoming.body.BTW}}",
"email":"{{G0IW.incoming.body.Email}}"
}
}
@Giuliano84
Giuliano84 / multiply.js
Last active January 10, 2018 14:07
code_block_multiply
//V1
module.exports = function(context, cb) {
const array = context.data.values;
const result = array.reduce(function(a,b){return a*b;});
cb(null, { result : result });
};
//V2
/*
module.exports = function (context, cb) {
var mysql = require('mysql@2.7.0');
var con = mysql.createConnection({
host: "localhost",
user: "yourusername",
password: "yourpassword",
database: "mydb"
});
@Giuliano84
Giuliano84 / w9parser.js
Created April 3, 2017 13:26
Code Block to parse W9 forms on Stamplay
function parseAddress(a) {if(typeof a!=="string") throw "Address is not a string.";a=a.trim();var r={},c=a.indexOf(',');r.city=a.slice(0,c);var f=a.substring(c+2),s=f.lastIndexOf(' ');r.state=f.slice(0,s);r.zip=f.substring(s+1);return r;}
module.exports = function(context, cb) {
//context.data contain the request body parameters
var result = {
name:"",
business_name:"",
address:"",
signed_at:"",
city:"",
export default (request) => {
const xhr = require('xhr');
// Send data to STAMPLAY
// This is a BLOCK to send arbitrary data to your Stamplay Trigger
// Paste here the Callback URL suggested by Stamplay
const STAMPLAY_HOOK = 'REPLACE_WITH_CALLBACK_URL';
function notifyStamplay (payload) {
@Giuliano84
Giuliano84 / codeblock.js
Created January 6, 2017 10:11
Example of update of attribute of a plainObject property of a Stamplay Object record
var Stamplay = require('stamplay')
var stamplay = new Stamplay('appId', 'apiKey')
module.exports = function(context, cb) {
/*
watson_context is the plainObject property of the object Conversation
let's grab it from the parameters passed as input to this code block (context.data)
and save it on a variable to make the edit we want
*/
/*
Conversation status:
- start
- selectItem
- itemQty
- itemConfirmed
- checkout
- confirmOrder
- confirmTime
/*
This snippet is part of the -- How to build a food ordering Kik bot tutorial --
You can find the complete tutorial here: LINK
*/
module.exports = function(context, cb) {
var stamplay = require('stamplay');
var Stamplay = new stamplay('APP_ID','API_KEY');
var responseMessage = {
chatId : context.data.chatId,
module.exports = function(context, cb) {
var Stamplay = require('stamplay');
var stamplay = new Stamplay('APP_ID', 'API_KEY');
//Retrieve subscription by number
stamplay.Object('subscription').get({number:encodeURIComponent(context.data.number)}, function(err, res){
var subscription = JSON.parse(res);
//If the subscription exists