Skip to content

Commit

Permalink
Merge branch 'master' into smd_sql
Browse files Browse the repository at this point in the history
  • Loading branch information
stevendavelaar committed Dec 22, 2022
2 parents 4e34ee2 + defc70f commit 755c705
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 0 deletions.
49 changes: 49 additions & 0 deletions bin/templates/components/dataqueryeventhandler/template.js
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 bin/templates/components/dataqueryeventhandler/template.ts
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);
}
}

0 comments on commit 755c705

Please sign in to comment.