-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsf-knowledge-base.js
53 lines (44 loc) · 1.92 KB
/
sf-knowledge-base.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
/* 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 violetKnowledgeResultsList = require('violet/lib/violetList-api')(violet, 'KnowledgeResults', 'article', 'articles', 'Title');
var violetSFStore = require('violet/lib/violetStoreSF')(violet);
violetSFStore.store.propOfInterest = {
'KnowledgeArticleVersion*': ['Id*', 'Title*', 'Summary*', 'UrlName*', 'LastPublishedDate*']
}
violet.addInputTypes({
"articleNo": "NUMBER",
"searchTerm": {
"type": "LITERAL",
"sampleValues": ["security", "data"]
}
});
violet.defineGoal({
goal: violetKnowledgeResultsList.interactionGoal(),
prompt: [`Would you like to hear more from an article or have an article sent to you.`],
respondTo: [{
expecting: [`{hear|} more about article [[articleNo]]`],
resolve: (response) => {
var article = violetKnowledgeResultsList.getItemFromResults(response, response.get('articleNo'));
response.say('Article ' + article.Title + ' has summary ' + article.Summary);
}}, {
expecting: [`send me article [[articleNo]]`],
resolve: function *(response) {
var itemObj = listWidget.getItemFromResults(response, response.get('articleNo'));
// item sending not implemented
response.say(humanName + ' ' + itemObj.Title + ' has been sent');
}}]
});
violet.respondTo({
expecting: ['I am looking for {information on|} [[searchTerm]]'],
resolve: function *(response) {
var results = yield response._persistentStoreReal().search('KnowledgeArticleVersion*', response.get('searchTerm'));
response.set('KnowledgeResults', results);
if (results.length == 0) {
response.say('Sorry. I did not find any information on [[searchTerm]].');
return;
}
violetKnowledgeResultsList.respondWithItems(response, results);
}});
module.exports = violet;