Skip to content

Commit 755c705

Browse files
Merge branch 'master' into smd_sql
2 parents 4e34ee2 + defc70f commit 755c705

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* eslint-disable no-unused-vars */
2+
3+
'use strict';
4+
5+
// You can use your favorite http client package to make REST calls, however, the node fetch API is pre-installed with the bots-node-sdk.
6+
// Documentation can be found at https://www.npmjs.com/package/node-fetch
7+
// Un-comment the next line if you want to make REST calls using node-fetch.
8+
// const fetch = require("node-fetch");
9+
10+
module.exports = {
11+
metadata: {
12+
name: '{{name}}',
13+
eventHandlerType: '{{eventHandlerType}}'
14+
},
15+
handlers: {
16+
entity: {
17+
/**
18+
* Default message handler that includes acknowledgements when a bag item is updated
19+
* or a bag item value is provided while the user was prompted for another item
20+
* @param {ChangeUISettingsEvent} event
21+
* @param {DataQueryResolutionContext} context
22+
*/
23+
changeUISettings: async (event, context) => {
24+
return event.settings;
25+
},
26+
27+
changeResponseData: async (event, context) => {
28+
return context.getQueryResult();
29+
},
30+
31+
changeBotMessages: async (event, context) => {
32+
return event.messages;
33+
}
34+
},
35+
attributes: {
36+
SomeAttributemName: { // TODO change to a valid attribute name
37+
// add attribute level event handlers here
38+
}
39+
// add more attributes and their handlers here
40+
},
41+
custom: {
42+
// add custom event handlers here
43+
}
44+
}
45+
};
46+
47+
/* eslint-enable no-unused-vars */
48+
49+
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { EntityResolutionContext
2+
, EntityEventHandler
3+
, EntityEventHandlers
4+
, EntityEventHandlerMetadata
5+
, EntityBaseEvent
6+
, EntityPublishMessageEvent
7+
} from '@oracle/bots-node-sdk/lib';
8+
9+
// You can use your favorite http client package to make REST calls, however, the node fetch API is pre-installed with the bots-node-sdk.
10+
// Documentation can be found at https://www.npmjs.com/package/node-fetch
11+
// Un-comment the next line if you want to make REST calls using node-fetch.
12+
// import fetch from 'node-fetch';
13+
14+
export class {{className}} implements EntityEventHandler {
15+
16+
public metadata(): EntityEventHandlerMetadata {
17+
return {
18+
name: '{{name}}',
19+
eventHandlerType: '{{eventHandlerType}}',
20+
supportedActions: [] // string array of transition actions that might be set by the event handler
21+
};
22+
}
23+
24+
public handlers(): EntityEventHandlers {
25+
return {
26+
27+
entity: {
28+
/**
29+
* Default message handler that includes acknowledgements when a bag item is updated
30+
* or a bag item value is provided while the user was prompted for another item
31+
*/
32+
publishMessage: async (event: EntityPublishMessageEvent, context: EntityResolutionContext) => {
33+
updatedItemsMessage(context);
34+
outOfOrderItemsMessage(context);
35+
context.addCandidateMessages();
36+
},
37+
38+
/**
39+
* This handler is called when the composite bag entity is resolved
40+
*/
41+
resolved: async (event: EntityBaseEvent, context: EntityResolutionContext) => { // eslint-disable-line no-unused-vars
42+
// add your back-end REST API call here
43+
}
44+
// add more entity level event handlers here
45+
},
46+
47+
items: {
48+
SomeBagItemName: { // TODO change to a valid bag item name
49+
// add item level event handlers here
50+
}
51+
// add more bag items and their handlers here
52+
},
53+
54+
custom: {
55+
// add custom event handlers here
56+
}
57+
58+
};
59+
}
60+
61+
}
62+
63+
/**
64+
* Helper function to show acknowledgement message when a bag item value is updated.
65+
*/
66+
function updatedItemsMessage(context: EntityResolutionContext) {
67+
if (context.getItemsUpdated().length > 0) {
68+
let message = "I have updated" + context.getItemsUpdated().map((item, i) => (i !== 0 ? " and the " : " the ") + item.toLowerCase() + " to " + context.getDisplayValue(item));
69+
context.addMessage(message);
70+
}
71+
}
72+
73+
/**
74+
* Helper function to show acknowledgement message when a bag item value is provided when user was prompted for anther bag item.
75+
*/
76+
function outOfOrderItemsMessage(context: EntityResolutionContext) {
77+
if (context.getItemsMatchedOutOfOrder().length > 0) {
78+
let message = "I got" + context.getItemsMatchedOutOfOrder().map((item, i) => (i !== 0 ? " and the " : " the ") + item.toLowerCase() + " " + context.getDisplayValue(item));
79+
context.addMessage(message);
80+
}
81+
}

0 commit comments

Comments
 (0)