Skip to content

Commit e495859

Browse files
New version 2.6.8:
Fixed doc error on casting of message payload Added data query context methods for upcoming ODA version 23.08
1 parent 8c92116 commit e495859

File tree

12 files changed

+179
-15
lines changed

12 files changed

+179
-15
lines changed

MESSAGE_FACTORY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,11 @@ When using TypeScript, you can cast to the proper message subclass to get design
406406
if (context.getRequest().state === context.getRequest().previousState) {
407407
const um = context.getUserMessage();
408408
if (um instanceof TextMessage) {
409-
const utm = um as typeof TextMessage;
409+
const utm = um as TextMessage;
410410
const text = utm.getText();
411411
// handle text
412412
} else if (um instanceof PostbackMessage) {
413-
const upm = um as typeof PostbackMessage;
413+
const upm = um as PostbackMessage;
414414
const postback = upm.getPostback();
415415
// handle postback payload
416416
...

RELEASE_NOTES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Release Notes
22

3+
- [Version 2.6.8](#v268)
34
- [Version 2.6.7](#v267)
45
- [Version 2.6.6](#v266)
56
- [Version 2.6.5](#v265)
@@ -17,6 +18,13 @@
1718
- [Version 2.4.3](#v243)
1819
- [Version 2.4.2](#v242)
1920

21+
## Version 2.6.8 <a name="v268">
22+
23+
### Fixed Issues
24+
25+
- Documentation fixes
26+
- Fixed issue in baseContext.translate method for TypeScript.
27+
2028
## Version 2.6.7 <a name="v267">
2129

2230
### New Features

lib/dataquery/dataQueryContext.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,44 @@ class DataQueryContext extends BaseContext {
176176
return this.getVariable('system.isFollowupResponse');
177177
}
178178

179+
/**
180+
* 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.
181+
* @param {string} action - the end flow action that can be used to transition in the main flow
182+
*/
183+
setEndFlowAction(action) {
184+
this.setVariable('system.sqlDialog.endFlowAction', action);
185+
this.getResponse().transitionAction = 'system.sqlDialog.endFlow';
186+
}
187+
188+
/**
189+
* Creates a postback action that ends the flow with the specified end flow action.
190+
* @param {string} the label of the postback button
191+
* @param {string} action - the end flow action that can be used to transition in the main flow
192+
*/
193+
createEndFlowPostbackAction(label, action) {
194+
const mf = this.getMessageFactory();
195+
return mf.createPostbackAction(label, {'action': 'system.sqlDialog.endFlow', 'variables': {'system.sqlDialog.endFlowAction': action}});
196+
}
197+
198+
/**
199+
* Invoke another flow
200+
* @param {string} flowName - name of the flow to invoke
201+
*/
202+
invokeFlow(flowName) {
203+
this.setVariable('system.sqlDialog.invokeFlowName', flowName);
204+
this.getResponse().transitionAction = 'system.sqlDialog.invokeFlow';
205+
}
206+
207+
/**
208+
* Creates a postback action that invokes the specified flow.
209+
* @param {string} the label of the postback button
210+
* @param {string} flowName - name of the flow to invoke
211+
*/
212+
createInvokeFlowPostbackAction(label, flowName) {
213+
const mf = this.getMessageFactory();
214+
return mf.createPostbackAction(label, {'action': 'system.sqlDialog.invokeFlow', 'variables': {'system.sqlDialog.invokeFlowName': flowName}});
215+
}
216+
179217
}
180218

181219
module.exports = { DataQueryContext }

lib/restservice/restServiceContext.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,36 @@ class RestServiceContext extends BaseContext {
7979
this.getResponse().responsePayload = payload;
8080
}
8181

82+
/**
83+
* Adds a message to the bot response sent to the user.
84+
* NOTE: This method can only be used in the validateResponsePayload handler
85+
* @param {object} payload - can take a string message, or a message created using the MessageFactory
86+
*/
87+
addMessage(payload) {
88+
this.getResponse().messages = this.getResponse().messages || [];
89+
this.getResponse().messages.push(super.constructMessagePayload(payload));
90+
}
91+
92+
/**
93+
* Set a transition action. When you use this function, the dialog engine will transition to the state defined for this transition action.
94+
* <p>
95+
* NOTE: This method can only be used in the validateResponsePayload handler
96+
* @param {string} action - name of the transition action
97+
*/
98+
setTransitionAction(action) {
99+
this.getResponse().transitionAction = action;
100+
}
101+
102+
/**
103+
* Sets an LLM prompt that will be sent to the LLM
104+
* <p>
105+
* NOTE: This method can only be used in the validateResponsePayload handler
106+
* @param {string} prompt - the text of the prompt
107+
*/
108+
setLLMPrompt(prompt) {
109+
this.getResponse().llmPrompt = prompt;
110+
}
111+
82112
}
83113

84114
module.exports = { RestServiceContext }

lib/restservice/utils.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,27 @@ async function invokeRestServiceEventHandlers(component, context) {
1616
// event handlers can be async (returning a promise), but we dont want to enforce
1717
// every event handler is async, hence Promise.resolve wrapping of invocation
1818
if (eventName === `transformRequestPayload`) {
19-
let payload = context.getRequestPayload();
20-
event.properties = {'payload': payload};
2119
logger.debug(`Invoking event handler ${eventName}`);
2220
let returnValue = await Promise.resolve(handler(event.properties, context));
2321
if (returnValue) {
2422
context.setRequestPayload(returnValue);
2523
}
2624
} else if (eventName === `transformResponsePayload` || eventName === `transformErrorResponsePayload`) {
27-
let payload = context.getResponsePayload();
28-
event.properties = {'payload': payload};
2925
logger.debug(`Invoking event handler ${eventName}`);
3026
let returnValue = await Promise.resolve(handler(event.properties, context));
3127
if (returnValue) {
3228
context.setResponsePayload(returnValue);
3329
}
30+
} else if (eventName === `validateResponsePayload`) {
31+
logger.debug(`Invoking event handler ${eventName}`);
32+
let returnValue = await Promise.resolve(handler(event.properties, context));
33+
// make sure return value is a boolean
34+
let retValue = returnValue === undefined ? true : (returnValue + '' === 'true')
35+
logger.debug(`${eventName} returned ${retValue}`);
36+
context.getResponse().valid = retValue;
3437
}
38+
39+
3540
} else {
3641
logger.debug(`No handler found for event: ${eventName}`);
3742
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@oracle/bots-node-sdk",
3-
"version": "2.6.7",
3+
"version": "2.6.8",
44
"description": "Oracle Digital Assistant SDK for custom component development and webhook integrations",
55
"main": "index.js",
66
"browser": "index-browser.js",

ts/lib/component/baseContext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,10 @@ export abstract class BaseContext {
360360
*/
361361
translate(rbKey: string, ...rbArgs: string[]) {
362362
// create freemarker expression that will be resolved in runtime after event handler or custom component response is received
363-
let exp = '${rb(\'' + rbKey + '\'';
363+
let exp = '${rb("' + rbKey + '"';
364364
for (let arg of rbArgs) {
365365
// MIECS-38051: only string args should be enclosed in quotes
366-
typeof arg === 'string' ? exp += ',\'' + arg + '\'' : exp += ',' + arg;
366+
typeof arg === 'string' ? exp += ',"' + arg + '"' : exp += ',' + arg;
367367
}
368368
exp += ')}';
369369
return exp;

ts/lib/dataquery/dataQueryContext.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,43 @@ export class DataQueryContext extends BaseContext {
179179
return this.getVariable('system.isFollowupResponse');
180180
}
181181

182+
/**
183+
* 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
184+
* main flow.
185+
* @param {string} action - the end flow action that can be used to transition in the main flow
186+
*/
187+
setEndFlowAction(action: string): void {
188+
this.setVariable('system.sqlDialog.endFlowAction', action);
189+
this.getResponse().transitionAction = 'system.sqlDialog.endFlow';
190+
}
191+
192+
/**
193+
* Creates a postback action that ends the flow with the specified end flow action.
194+
* @param {string} the label of the postback button
195+
* @param {string} action - the end flow action that can be used to transition in the main flow
196+
*/
197+
createEndFlowPostbackAction(label: string, action: string): PostbackAction {
198+
const mf = this.getMessageFactory();
199+
return mf.createPostbackAction(label, {'action': 'system.sqlDialog.endFlow', 'variables': {'system.sqlDialog.endFlowAction': action}});
200+
}
201+
202+
/**
203+
* Invoke another flow
204+
* @param {string} flowName - name of the flow to invoke
205+
*/
206+
invokeFlow(flowName: string): void {
207+
this.setVariable('system.sqlDialog.invokeFlowName', flowName);
208+
this.getResponse().transitionAction = 'system.sqlDialog.invokeFlow';
209+
}
210+
211+
/**
212+
* Creates a postback action that invokes the specified flow.
213+
* @param {string} the label of the postback button
214+
* @param {string} flowName - name of the flow to invoke
215+
*/
216+
createInvokeFlowPostbackAction(label, flowName): PostbackAction {
217+
const mf = this.getMessageFactory();
218+
return mf.createPostbackAction(label, {'action': 'system.sqlDialog.invokeFlow',
219+
'variables': {'system.sqlDialog.invokeFlowName': flowName}});
220+
}
182221
}

ts/lib/restservice/restServiceContext.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { BaseContext } from '../component/baseContext';
2+
import { MessagePayload } from '../message';
23

34
// Response template
45
const RESPONSE = {
@@ -74,8 +75,38 @@ export class RestServiceContext extends BaseContext {
7475
/**
7576
* Set the response payload
7677
*/
77-
setResponsePayload(payload: any) {
78+
setResponsePayload(payload: any): void {
7879
this.getResponse().responsePayload = payload;
7980
}
8081

82+
/**
83+
* Adds a message to the bot response sent to the user.
84+
* NOTE: This method can only be used in the validateResponsePayload handler
85+
* @param {object} payload - can take a string message, or a message created using the MessageFactory
86+
*/
87+
addMessage(payload: string | MessagePayload): void {
88+
this.getResponse().messages = this.getResponse().messages || [];
89+
this.getResponse().messages.push(super.constructMessagePayload(payload));
90+
}
91+
92+
/**
93+
* Set a transition action. When you use this function, the dialog engine will transition to the state defined for this transition action.
94+
* <p>
95+
* NOTE: This method can only be used in the validateResponsePayload handler
96+
* @param {string} action - name of the transition action
97+
*/
98+
setTransitionAction(action: string): void {
99+
this.getResponse().transitionAction = action;
100+
}
101+
102+
/**
103+
* Sets an LLM prompt that will be sent to the LLM
104+
* <p>
105+
* NOTE: This method can only be used in the validateResponsePayload handler
106+
* @param {string} prompt - the text of the prompt
107+
*/
108+
setLLMPrompt(prompt: string): void {
109+
this.getResponse().llmPrompt = prompt;
110+
}
111+
81112
}

0 commit comments

Comments
 (0)