-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
bin/templates/components/dataqueryeventhandler/template.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* eslint-disable no-unused-vars */ | ||
|
||
'use strict'; | ||
|
||
// 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. | ||
// Documentation can be found at https://www.npmjs.com/package/node-fetch | ||
// Un-comment the next line if you want to make REST calls using node-fetch. | ||
// const fetch = require("node-fetch"); | ||
|
||
module.exports = { | ||
metadata: { | ||
name: '{{name}}', | ||
eventHandlerType: '{{eventHandlerType}}' | ||
}, | ||
handlers: { | ||
entity: { | ||
/** | ||
* Default message handler that includes acknowledgements when a bag item is updated | ||
* or a bag item value is provided while the user was prompted for another item | ||
* @param {ChangeUISettingsEvent} event | ||
* @param {DataQueryResolutionContext} context | ||
*/ | ||
changeUISettings: async (event, context) => { | ||
return event.settings; | ||
}, | ||
|
||
changeResponseData: async (event, context) => { | ||
return context.getQueryResult(); | ||
}, | ||
|
||
changeBotMessages: async (event, context) => { | ||
return event.messages; | ||
} | ||
}, | ||
attributes: { | ||
SomeAttributemName: { // TODO change to a valid attribute name | ||
// add attribute level event handlers here | ||
} | ||
// add more attributes and their handlers here | ||
}, | ||
custom: { | ||
// add custom event handlers here | ||
} | ||
} | ||
}; | ||
|
||
/* eslint-enable no-unused-vars */ | ||
|
||
|
81 changes: 81 additions & 0 deletions
81
bin/templates/components/dataqueryeventhandler/template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { EntityResolutionContext | ||
, EntityEventHandler | ||
, EntityEventHandlers | ||
, EntityEventHandlerMetadata | ||
, EntityBaseEvent | ||
, EntityPublishMessageEvent | ||
} from '@oracle/bots-node-sdk/lib'; | ||
|
||
// 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. | ||
// Documentation can be found at https://www.npmjs.com/package/node-fetch | ||
// Un-comment the next line if you want to make REST calls using node-fetch. | ||
// import fetch from 'node-fetch'; | ||
|
||
export class {{className}} implements EntityEventHandler { | ||
|
||
public metadata(): EntityEventHandlerMetadata { | ||
return { | ||
name: '{{name}}', | ||
eventHandlerType: '{{eventHandlerType}}', | ||
supportedActions: [] // string array of transition actions that might be set by the event handler | ||
}; | ||
} | ||
|
||
public handlers(): EntityEventHandlers { | ||
return { | ||
|
||
entity: { | ||
/** | ||
* Default message handler that includes acknowledgements when a bag item is updated | ||
* or a bag item value is provided while the user was prompted for another item | ||
*/ | ||
publishMessage: async (event: EntityPublishMessageEvent, context: EntityResolutionContext) => { | ||
updatedItemsMessage(context); | ||
outOfOrderItemsMessage(context); | ||
context.addCandidateMessages(); | ||
}, | ||
|
||
/** | ||
* This handler is called when the composite bag entity is resolved | ||
*/ | ||
resolved: async (event: EntityBaseEvent, context: EntityResolutionContext) => { // eslint-disable-line no-unused-vars | ||
// add your back-end REST API call here | ||
} | ||
// add more entity level event handlers here | ||
}, | ||
|
||
items: { | ||
SomeBagItemName: { // TODO change to a valid bag item name | ||
// add item level event handlers here | ||
} | ||
// add more bag items and their handlers here | ||
}, | ||
|
||
custom: { | ||
// add custom event handlers here | ||
} | ||
|
||
}; | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Helper function to show acknowledgement message when a bag item value is updated. | ||
*/ | ||
function updatedItemsMessage(context: EntityResolutionContext) { | ||
if (context.getItemsUpdated().length > 0) { | ||
let message = "I have updated" + context.getItemsUpdated().map((item, i) => (i !== 0 ? " and the " : " the ") + item.toLowerCase() + " to " + context.getDisplayValue(item)); | ||
context.addMessage(message); | ||
} | ||
} | ||
|
||
/** | ||
* Helper function to show acknowledgement message when a bag item value is provided when user was prompted for anther bag item. | ||
*/ | ||
function outOfOrderItemsMessage(context: EntityResolutionContext) { | ||
if (context.getItemsMatchedOutOfOrder().length > 0) { | ||
let message = "I got" + context.getItemsMatchedOutOfOrder().map((item, i) => (i !== 0 ? " and the " : " the ") + item.toLowerCase() + " " + context.getDisplayValue(item)); | ||
context.addMessage(message); | ||
} | ||
} |