-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsf-cases-customer.js
75 lines (61 loc) · 2.34 KB
/
sf-cases-customer.js
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* Copyright (c) 2017-present, salesforce.com, inc. All rights reserved */
/* Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license */
'use strict';
var violet = require('violet').script();
var violetSFStore = require('violet/lib/violetStoreSF')(violet);
violetSFStore.store.propOfInterest = {
'Case*': ['CaseNumber*', 'Contact*.Name*', /*'Contact*.Owner*.Name*',*/ 'Subject*', 'Status*', 'Priority*']
}
violet.addInputTypes({
"name": "AMAZON.LITERAL",
"company": "AMAZON.LITERAL",
"opportunityName": "AMAZON.LITERAL",
});
// implement login - as a function of how we deploy
const userName = 'Stella Pavlova';
violet.respondTo({
expecting: ['status of my cases'],
resolve: function *(response) {
var results = yield response.load('Case*', 'Contact*.Name*', userName);
if (results.length == 0) {
response.say('Sorry. You have no cases.');
return;
}
// iterate through results and collect states in object 'status'
var status = {};
results.forEach((c)=>{
if (!status[c.Status]) status[c.Status] = 0;
status[c.Status]++;
});
var out = 'You have ' + results.length + ' cases. Of these'
var states = Object.keys(status);
states.forEach((s,ndx)=>{
if (status[s]==1)
out += status[s] + ' is ' + s;
else
out += status[s] + ' are ' + s;
if (ndx == states.length-2) out += ' and ';
});
response.say(out);
}});
violet.respondTo({
expecting: ['which case of mine changed states most recently'],
resolve: function *(response) {
var results = yield response.load('Case*', 'Contact*.Name*', 'Stella Pavlova', null, 'order by LastModifiedDate limit 1');
if (results.length == 0) {
response.say('Sorry. You have no cases.');
return;
}
var caseObj = results[0];
response.say('Your case ' + caseObj.Subject + ' has status ' + caseObj.Status + ' and priority ' + caseObj.Priority);
}});
violet.respondTo({
expecting: ['tell me when one of my cases changes state'],
resolve: function *(response) {
response.say('Sure');
// TODO: put a hook in sfdc, when we hear back, do the below (and test that it works)
// TODO: test and implement below
//violet.sendAlertMessage('One of your cases has changed state');
//... in violet implennt as `_setAlert('message')` and have callback to clear
}});
module.exports = violet;