This repository has been archived by the owner on Feb 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createEventForSalesForce.json
25 lines (25 loc) · 2.21 KB
/
createEventForSalesForce.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{
"name": "createEventForSalesForce",
"version": "0.0.19",
"type": "actuator",
"script": "const jsforce = require('jsforce')\nconst pify = require('pify')\nconst Waylay = require('@waylay/client')\nconst _ = require('lodash')\nconst moment = require('moment')\n\nasync function main () {\n const caseObject = cleanObject({\n Subject: options.requiredProperties.subject,\n Location: options.requiredProperties.location,\n ActivityDateTime: moment().toISOString(),\n DurationInMinutes: options.requiredProperties.duration || 1\n })\n\n if (!caseObject.Subject) {\n send(new Error('No subject provided'))\n }\n\n const conn = await getSalesforceConnection()\n const SfEvent = pify(conn.sobject('Event'))\n\n const res = await SfEvent.create(caseObject)\n\n send(null, { message: JSON.stringify(res) })\n}\n\nasync function getSalesforceConnection () {\n try {\n const waylayClient = new Waylay({\n token: options.globalSettings.waylayToken\n })\n\n const { access_token: accessToken } = await waylayClient.hoard.getTokens('salesforce', { scope: 'organisation' })\n\n if (!accessToken) {\n throw new Error('No user or token provided via Hoard service')\n }\n\n const jsclient = new jsforce.Connection({\n instanceUrl: 'https://eu26.salesforce.com',\n accessToken\n })\n\n return jsclient\n } catch (error) {\n throw new Error(`error: ${error} \\n possible solution: Connect Salesforce through the connections`)\n }\n}\n\n/**\n * remove empty values in object before sending to salesforce\n */\nfunction cleanObject (object) {\n return _.reduce(object, (acc, v, k) => {\n if (v) acc[k] = v\n return acc\n }, {})\n}\n\nmain().catch(send)\n",
"metadata": {
"author": "",
"iconURL": "https://static.waylay.io/plugs/icons/create-event-for-salesforce.png",
"description": "Create event for the salesforce.\nSubject is mandatory, if duration is not given it default \nvalue is 1min.",
"rawData": [],
"requiredProperties": [
"subject",
"location",
"duration"
],
"supportedStates": []
},
"dependencies": {
"jsforce": "1.10.0",
"pify": "5.0.0",
"@waylay/client": "2.20.0",
"lodash": "4.17.15",
"moment": "2.29.1"
}
}