Skip to content

Commit c471667

Browse files
- moved translate function from entityResolutionContext to baseContext
- added function getChannelType to baseContext - added function addGlobalAction to message model
1 parent 2f68b45 commit c471667

File tree

10 files changed

+84
-33
lines changed

10 files changed

+84
-33
lines changed

MESSAGE_MODEL.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ const messageModel = context.getMessageModel();
9696
let keywords = [];
9797
keywords.push( messageModel.postbackKeyword(["1","first"], {"variables" : {"pizzaSize": "small"}}));
9898
keywords.push( messageModel.postbackKeyword(["2","second"], {"variables" : {"pizzaSize": "medium"}}));
99-
keywords.push( messageModel.postbackKeyword(["1","third"], {"variables" : {"pizzaSize": "large"}}));
99+
keywords.push( messageModel.postbackKeyword(["3","third"], {"variables" : {"pizzaSize": "large"}}));
100100
let textMessage = messageModel.textConversationMessage('What pizza size do you want?\n1. Small\n2. Medium\n3. Large', undefined, undefined, undefined, keywords);
101101
context.reply(textMessage);
102102
```
@@ -180,7 +180,7 @@ module.exports = {
180180
name: 'orderConfirmation'
181181
}),
182182
invoke: (context, done) => {
183-
if (context.getRequest().message.channelConversation.type ==='msteams') {
183+
if (context.getChannelType() === 'msteams') {
184184
context.reply(context.getMessageModel().rawConversationMessage(card));
185185
} else {
186186
context.reply('Thank you for ordering a PEPPERONI piza, have a nice day!');
@@ -190,7 +190,7 @@ module.exports = {
190190
}
191191
};
192192
```
193-
Because the skill might use multiple channels, only send the adaptve card for the `msteams` channel.
193+
Because the skill might use multiple channels, we only send the adaptive card for the `msteams` channel.
194194
The actual adaptive card payload is defined in `card.json`, which looks like this:
195195

196196
```javascript

RELEASE_NOTES.md

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

3+
- [Version 2.5.5](#v255)
34
- [Version 2.5.4](#v254)
45
- [Version 2.5.3](#v253)
56
- [Version 2.5.2](#v252)
@@ -8,6 +9,14 @@
89
- [Version 2.4.3](#v243)
910
- [Version 2.4.2](#v242)
1011

12+
## Version 2.5.5 <a name="v255">
13+
14+
### New Features
15+
16+
- **Support for resource bundles in custom components**: The `context.translate` function that was already available for entity event handlers, can now be used with custom components as well. The function takes a resource bundle key and optionally a list of sustitution variables. Note that use of this function requires digital assistant version 21.06 or higher.
17+
- **Convenience method to get channel type**: A new function `context.getChannelType` has been added for both custom components and entity event handler.
18+
- **Convenience method to add a global action**: A new function `messageModel.addGlobalAction` has been added to the message model. This method adds a single globl action without removing any existing global actions.
19+
1120
## Version 2.5.4 <a name="v254">
1221

1322
### Fixed Issues

lib/component/baseContext.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,27 @@ class BaseContext {
174174
return this.variable(name,value);
175175
}
176176

177+
/**
178+
* Get translated string using a resource bundle key defined in the skill.
179+
* @return {string} resource bundle freemarker expression that will be resolved when event handler or custom component response is
180+
* received by dialog engine
181+
* @param {string} rbKey - key of the resource bundle entry defined with the skill that should be used to translate
182+
* @param {string} rbArgs - substitution variables
183+
*/
184+
translate(rbKey, ...rbArgs) {
185+
// create freemarker expression that will be resolved in runtime after event handler or custom component response is received
186+
let exp = "${rb('"+rbKey+"','"+rbArgs.join('\',\'')+"')}";
187+
return exp;
188+
}
189+
190+
/**
191+
* Return the channel conversation type
192+
* @return {string} the channel type
193+
*/
194+
getChannelType() {
195+
return this.getRequest().message.channelConversation.type;
196+
}
197+
177198
/**
178199
* Returns the MessageModel class for creating or validating messages to or from bots.
179200
* @see MessageModel.js

lib/entity/entityResolutionContext.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -398,19 +398,6 @@ class EntityResolutionContext extends BaseContext {
398398
this.getResponse().cancel = true;
399399
}
400400

401-
/**
402-
* Get translated string using a resource bundle key defined in the skill.
403-
* IMPORTANT: for this method to work the resource bundle must be defined as a context variable in the dialog flow using the name 'rb'.
404-
* @return {string} resource bundle freemarker expression that will be resolved when event handler response is received by dialog engine
405-
* @param {string} rbKey - key of the resource bundle entry defined with the skill that should be used to translate
406-
* @param {string} rbArgs - substitution variables
407-
*/
408-
translate(rbKey, ...rbArgs) {
409-
// create freemarker expression that will be resolved in runtime after event handler response is received
410-
let exp = "${rb('"+rbKey+"','"+rbArgs.join('\',\'')+"')}";
411-
return exp;
412-
}
413-
414401
/**
415402
* Sets the value of a custom property that is stored in the entity resolution context. A custom property can be
416403
* used to maintain custom state accross event handler calls while resolving the composite bag entity.

lib/message/messageModel.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ class MessageModel {
418418
}
419419

420420
/**
421-
* Static method to add global actions to a payload object.
421+
* Static method to add global actions to a message payload object. This method replaces any existing global actions.
422422
* @return {object} A ConversationMessage with global actions.
423423
* @param {object} message - The message to add global actions to.
424424
* @param {object} globalActions - The global actions to be added.
@@ -430,6 +430,19 @@ class MessageModel {
430430
return message;
431431
}
432432

433+
/**
434+
* Static method to add a global action to a message payload object.
435+
* @return {object} A ConversationMessage with global actions.
436+
* @param {object} message - The message to add the global action to.
437+
* @param {object} globalAction - The global action to be added.
438+
*/
439+
static addGlobalAction(message, globalAction) {
440+
let globalActions = message.globalActions || [];
441+
globalActions.push(globalAction);
442+
message.globalActions = globalActions;
443+
return message;
444+
}
445+
433446
/**
434447
* Static method to validate a common ConversationMessage
435448
* @return {boolean|object} true if valid; return Validation Error object (error & value) if invalid

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.5.4",
3+
"version": "2.5.5",
44
"description": "Oracle Bots SDK for custom component development and webhook integrations",
55
"main": "index.js",
66
"browser": "index-browser.js",

ts/lib/component/baseContext.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,27 @@ export abstract class BaseContext {
180180
return this.variable(name, value);
181181
}
182182

183+
/**
184+
* Get translated string using a resource bundle key defined in the skill.
185+
* @return {string} resource bundle freemarker expression that will be resolved when event handler or custom component response is
186+
* received by dialog engine
187+
* @param {string} rbKey - key of the resource bundle entry defined with the skill that should be used to translate
188+
* @param {string} rbArgs - substitution variables
189+
*/
190+
translate(rbKey: string, ...rbArgs: string[]) {
191+
// create freemarker expression that will be resolved in runtime after event handler or custom component response is received
192+
let exp = '${rb(\'' + rbKey + '\',\'' + rbArgs.join('\', \'') + '\')}';
193+
return exp;
194+
}
195+
196+
/**
197+
* Return the channel conversation type
198+
* @return {string} the channel type
199+
*/
200+
getChannelType(): string {
201+
return this.getRequest().message.channelConversation.type;
202+
}
203+
183204
/**
184205
* Returns the MessageModel class for creating or validating messages to or from bots.
185206
* @see MessageModel.js

ts/lib/entity/entityResolutionContext.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -439,19 +439,6 @@ export class EntityResolutionContext extends BaseContext {
439439
this.getResponse().cancel = true;
440440
}
441441

442-
/**
443-
* Get translated string using a resource bundle key defined in the skill.
444-
* IMPORTANT: for this method to work the resource bundle must be defined as a context variable in the dialog flow using the name 'rb'.
445-
* @return {string} resource bundle freemarker expression that will be resolved when event handler response is received by dialog engine
446-
* @param {string} rbKey - key of the resource bundle entry defined with the skill that should be used to translate
447-
* @param {string} rbArgs - substitution variables
448-
*/
449-
translate(rbKey: string, ...rbArgs: string[]) {
450-
// create freemarker expression that will be resolved in runtime after event handler response is received
451-
let exp = '${rb(\'' + rbKey + '\',\'' + rbArgs.join('\', \'') + '\')}';
452-
return exp;
453-
}
454-
455442
/**
456443
* Sets the value of a custom property that is stored in the entity resolution context. A custom property can be
457444
* used to maintain custom state accross event handler calls while resolving the composite bag entity.

ts/lib/message/messageModel.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ export class MessageModel {
416416
}
417417

418418
/**
419-
* Static utility method to add global actions to a payload
419+
* Static method to add global actions to a message payload object. This method replaces any existing global actions.
420420
* @return A ConversationMessage with global actions.
421421
* @param message - The message to add global actions to.
422422
* @param globalActions - The global actions to be added.
@@ -428,6 +428,19 @@ export class MessageModel {
428428
return message;
429429
}
430430

431+
/**
432+
* Static method to add a global action to a message payload object.
433+
* @return A ConversationMessage with global actions.
434+
* @param message - The message to add the global action to.
435+
* @param globalAction - The global action to be added.
436+
*/
437+
static addGlobalAction(message: NonRawMessagePayload, globalAction: Action): NonRawMessagePayload {
438+
let globalActions = message.globalActions || [];
439+
globalActions.push(globalAction);
440+
message.globalActions = globalActions;
441+
return message;
442+
}
443+
431444
/**
432445
* Static utility method to validate a common ConversationMessage
433446
* @return true if valid; return Validation Error object (error & value) if invalid

0 commit comments

Comments
 (0)