Skip to content

Commit

Permalink
New release 2.6.8 (#46)
Browse files Browse the repository at this point in the history
New version 2.6.8:
Fixed doc error on casting of message payload
Added data query context methods for upcoming ODA version 23.08
  • Loading branch information
stevendavelaar committed Jul 25, 2023
1 parent bbe81e4 commit 3148e06
Show file tree
Hide file tree
Showing 14 changed files with 179 additions and 145 deletions.
4 changes: 2 additions & 2 deletions MESSAGE_FACTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,11 @@ When using TypeScript, you can cast to the proper message subclass to get design
if (context.getRequest().state === context.getRequest().previousState) {
const um = context.getUserMessage();
if (um instanceof TextMessage) {
const utm = um as typeof TextMessage;
const utm = um as TextMessage;
const text = utm.getText();
// handle text
} else if (um instanceof PostbackMessage) {
const upm = um as typeof PostbackMessage;
const upm = um as PostbackMessage;
const postback = upm.getPostback();
// handle postback payload
...
Expand Down
8 changes: 8 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Release Notes

- [Version 2.6.8](#v268)
- [Version 2.6.7](#v267)
- [Version 2.6.6](#v266)
- [Version 2.6.5](#v265)
Expand All @@ -17,6 +18,13 @@
- [Version 2.4.3](#v243)
- [Version 2.4.2](#v242)

## Version 2.6.8 <a name="v268">

### Fixed Issues

- Documentation fixes
- Fixed issue in baseContext.translate method for TypeScript.

## Version 2.6.7 <a name="v267">

### New Features
Expand Down
49 changes: 0 additions & 49 deletions bin/templates/components/dataqueryeventhandler/template.js

This file was deleted.

81 changes: 0 additions & 81 deletions bin/templates/components/dataqueryeventhandler/template.ts

This file was deleted.

38 changes: 38 additions & 0 deletions lib/dataquery/dataQueryContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,44 @@ class DataQueryContext extends BaseContext {
return this.getVariable('system.isFollowupResponse');
}

/**
* The end flow action that is set that can be used to transition to a different flow by defining a mapping for this action in the main flow.
* @param {string} action - the end flow action that can be used to transition in the main flow
*/
setEndFlowAction(action) {
this.setVariable('system.sqlDialog.endFlowAction', action);
this.getResponse().transitionAction = 'system.sqlDialog.endFlow';
}

/**
* Creates a postback action that ends the flow with the specified end flow action.
* @param {string} the label of the postback button
* @param {string} action - the end flow action that can be used to transition in the main flow
*/
createEndFlowPostbackAction(label, action) {
const mf = this.getMessageFactory();
return mf.createPostbackAction(label, {'action': 'system.sqlDialog.endFlow', 'variables': {'system.sqlDialog.endFlowAction': action}});
}

/**
* Invoke another flow
* @param {string} flowName - name of the flow to invoke
*/
invokeFlow(flowName) {
this.setVariable('system.sqlDialog.invokeFlowName', flowName);
this.getResponse().transitionAction = 'system.sqlDialog.invokeFlow';
}

/**
* Creates a postback action that invokes the specified flow.
* @param {string} the label of the postback button
* @param {string} flowName - name of the flow to invoke
*/
createInvokeFlowPostbackAction(label, flowName) {
const mf = this.getMessageFactory();
return mf.createPostbackAction(label, {'action': 'system.sqlDialog.invokeFlow', 'variables': {'system.sqlDialog.invokeFlowName': flowName}});
}

}

module.exports = { DataQueryContext }
30 changes: 30 additions & 0 deletions lib/restservice/restServiceContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,36 @@ class RestServiceContext extends BaseContext {
this.getResponse().responsePayload = payload;
}

/**
* Adds a message to the bot response sent to the user.
* NOTE: This method can only be used in the validateResponsePayload handler
* @param {object} payload - can take a string message, or a message created using the MessageFactory
*/
addMessage(payload) {
this.getResponse().messages = this.getResponse().messages || [];
this.getResponse().messages.push(super.constructMessagePayload(payload));
}

/**
* Set a transition action. When you use this function, the dialog engine will transition to the state defined for this transition action.
* <p>
* NOTE: This method can only be used in the validateResponsePayload handler
* @param {string} action - name of the transition action
*/
setTransitionAction(action) {
this.getResponse().transitionAction = action;
}

/**
* Sets an LLM prompt that will be sent to the LLM
* <p>
* NOTE: This method can only be used in the validateResponsePayload handler
* @param {string} prompt - the text of the prompt
*/
setLLMPrompt(prompt) {
this.getResponse().llmPrompt = prompt;
}

}

module.exports = { RestServiceContext }
13 changes: 9 additions & 4 deletions lib/restservice/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,27 @@ async function invokeRestServiceEventHandlers(component, context) {
// event handlers can be async (returning a promise), but we dont want to enforce
// every event handler is async, hence Promise.resolve wrapping of invocation
if (eventName === `transformRequestPayload`) {
let payload = context.getRequestPayload();
event.properties = {'payload': payload};
logger.debug(`Invoking event handler ${eventName}`);
let returnValue = await Promise.resolve(handler(event.properties, context));
if (returnValue) {
context.setRequestPayload(returnValue);
}
} else if (eventName === `transformResponsePayload` || eventName === `transformErrorResponsePayload`) {
let payload = context.getResponsePayload();
event.properties = {'payload': payload};
logger.debug(`Invoking event handler ${eventName}`);
let returnValue = await Promise.resolve(handler(event.properties, context));
if (returnValue) {
context.setResponsePayload(returnValue);
}
} else if (eventName === `validateResponsePayload`) {
logger.debug(`Invoking event handler ${eventName}`);
let returnValue = await Promise.resolve(handler(event.properties, context));
// make sure return value is a boolean
let retValue = returnValue === undefined ? true : (returnValue + '' === 'true')
logger.debug(`${eventName} returned ${retValue}`);
context.getResponse().valid = retValue;
}


} else {
logger.debug(`No handler found for event: ${eventName}`);
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oracle/bots-node-sdk",
"version": "2.6.7",
"version": "2.6.8",
"description": "Oracle Digital Assistant SDK for custom component development and webhook integrations",
"main": "index.js",
"browser": "index-browser.js",
Expand Down
4 changes: 2 additions & 2 deletions ts/lib/component/baseContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,10 @@ export abstract class BaseContext {
*/
translate(rbKey: string, ...rbArgs: string[]) {
// create freemarker expression that will be resolved in runtime after event handler or custom component response is received
let exp = '${rb(\'' + rbKey + '\'';
let exp = '${rb("' + rbKey + '"';
for (let arg of rbArgs) {
// MIECS-38051: only string args should be enclosed in quotes
typeof arg === 'string' ? exp += ',\'' + arg + '\'' : exp += ',' + arg;
typeof arg === 'string' ? exp += ',"' + arg + '"' : exp += ',' + arg;
}
exp += ')}';
return exp;
Expand Down
39 changes: 39 additions & 0 deletions ts/lib/dataquery/dataQueryContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,43 @@ export class DataQueryContext extends BaseContext {
return this.getVariable('system.isFollowupResponse');
}

/**
* The end flow action that is set that can be used to transition to a different flow by defining a mapping for this action in the
* main flow.
* @param {string} action - the end flow action that can be used to transition in the main flow
*/
setEndFlowAction(action: string): void {
this.setVariable('system.sqlDialog.endFlowAction', action);
this.getResponse().transitionAction = 'system.sqlDialog.endFlow';
}

/**
* Creates a postback action that ends the flow with the specified end flow action.
* @param {string} the label of the postback button
* @param {string} action - the end flow action that can be used to transition in the main flow
*/
createEndFlowPostbackAction(label: string, action: string): PostbackAction {
const mf = this.getMessageFactory();
return mf.createPostbackAction(label, {'action': 'system.sqlDialog.endFlow', 'variables': {'system.sqlDialog.endFlowAction': action}});
}

/**
* Invoke another flow
* @param {string} flowName - name of the flow to invoke
*/
invokeFlow(flowName: string): void {
this.setVariable('system.sqlDialog.invokeFlowName', flowName);
this.getResponse().transitionAction = 'system.sqlDialog.invokeFlow';
}

/**
* Creates a postback action that invokes the specified flow.
* @param {string} the label of the postback button
* @param {string} flowName - name of the flow to invoke
*/
createInvokeFlowPostbackAction(label, flowName): PostbackAction {
const mf = this.getMessageFactory();
return mf.createPostbackAction(label, {'action': 'system.sqlDialog.invokeFlow',
'variables': {'system.sqlDialog.invokeFlowName': flowName}});
}
}
Loading

0 comments on commit 3148e06

Please sign in to comment.