You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CUSTOM_COMPONENT.md
+16-80Lines changed: 16 additions & 80 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,7 +43,7 @@ The custom component must export two objects:
43
43
- Supported transition actions
44
44
- The `invoke` function, which contains the logic to execute
45
45
46
-
Here's an example of how to use both objects. Note that the first argument (`context`) names the reference to the [CustomComponentContext](https://oracle.github.io/bots-node-sdk/CustomComponentContext.html) object, which provides a context object for reading and changing variables as well as sending back results.
46
+
Here's an example of how to use both objects. Note that the argument (`context`) names the reference to the [CustomComponentContext](https://oracle.github.io/bots-node-sdk/CustomComponentContext.html) object, which provides a context object for reading and changing variables as well as sending back results.
47
47
48
48
> **Note:** Before version 2.5.1, many code examples named the first argument `conversation`. Either name is valid.
49
49
@@ -58,7 +58,7 @@ module.exports = {
58
58
supportedActions: ['weekday', 'weekend']
59
59
},
60
60
61
-
invoke: (context, done) => {
61
+
invoke:async(context) => {
62
62
// Retrieve the value of the 'human' component property.
63
63
const { human } =context.properties();
64
64
// determine date
@@ -69,7 +69,6 @@ module.exports = {
69
69
context.reply(`Greetings ${human}`)
70
70
.reply(`Today is ${now.toLocaleDateString()}, a ${dayOfWeek}`)
71
71
.transition(isWeekend ?'weekend':'weekday');
72
-
done();
73
72
}
74
73
}
75
74
```
@@ -90,20 +89,6 @@ module.exports = {
90
89
...
91
90
}
92
91
```
93
-
Bots Node SDK version 2.5.1 introduced an alternative syntax for the `invoke` method, which uses an `async` keyword instead of the `done` argument.
94
-
95
-
```javascript
96
-
invoke:async (context) => {
97
-
...
98
-
context.reply('hello world');
99
-
}
100
-
```
101
-
You can use this syntax in the following cases:
102
-
- You'll deploy to an embedded container in a Digital Assistance instance of version 21.02 or higher
103
-
- You'll deploy to a host other than the embedded container and your component package uses Bots Node SDK version 2.5.1 or higher
104
-
105
-
With the `async` function definition, you can write asynchronous code in a synchronous way using the `await` keyword.
106
-
In addition, you no longer have to call `done()` at every place in your code where the custom component logic is completed.
107
92
108
93
### Using TypeScript <aname="ts">
109
94
@@ -121,7 +106,7 @@ When you use TypeScript, the custom component class must implement the `CustomCo
121
106
The following code shows an example of defining the two methods.
- You'll deploy to an embedded container in a Digital Assistance instance of version 21.02 or higher
162
-
- You'll deploy to a host other than the embedded container and your component package uses Bots Node SDK version 2.5.1 or higher
163
-
164
-
With the `async` function definition, you can write asynchronous code in a synchronous way using the `await` keyword.
165
-
In addition, you no longer have to call `done()` at every place in your code where the custom component logic is completed.
166
138
167
139
### The Metadata Object <aname="metadata">
168
140
@@ -184,7 +156,7 @@ The `supportedActions` aren't checked at runtime. If you call the `transition(ac
184
156
185
157
The `invoke` method contains all the logic. In this method you can read and write skill context variables, create conversation messages, set state transitions, make REST calls, and more.
186
158
187
-
The first argument of the `invoke` method is the `context` object. This object references the [CustomComponentContext](https://oracle.github.io/bots-node-sdk/CustomComponentContext.html), which provides access to many convenience methods to create your logic.
159
+
The argument of the `invoke` method is the `context` object. This object references the [CustomComponentContext](https://oracle.github.io/bots-node-sdk/CustomComponentContext.html), which provides access to many convenience methods to create your logic.
188
160
189
161
More information about creating conversation messages to send to the skill user can be found [here](https://github.com/oracle/bots-node-sdk/blob/master/MESSAGE_MODEL.md).
190
162
@@ -198,12 +170,11 @@ You use different combinations of the [CustomComponentContext](https://oracle.gi
198
170
If you don't call `transition()`, the response is sent but the dialog stays in the state and subsequent user input comes back to this component. That is, `invoke()` is called again.
199
171
200
172
```javascript
201
-
invoke: (context, done) => {
173
+
invoke:async(context) => {
202
174
...
203
175
context.reply(payload);
204
176
context.keepTurn(true);
205
177
context.transition ("success");
206
-
done();
207
178
}
208
179
```
209
180
Here's a list of typical combinations of `keepTurn()` and `transition()` that you can use depending on the use case:
let _latitude =context.getVariable(latitudeVariable);
332
272
// ...
333
-
done();
334
273
} else {
335
-
done(newError('State is missing latitudeVariable property.'));
274
+
thrownewError('State is missing latitudeVariable property.');
336
275
}
337
276
```
338
277
@@ -352,15 +291,14 @@ On the skill's **Settings** tab, add the custom parameter and provide a value (o
352
291
Add a `metadata` property to pass in the name of the variable, and then call `context.setVariable(<variable name>, <value>)` to set the value. For example:
// Navigate to next state without first prompting for user interaction.
361
300
context.keepTurn(true);
362
301
context.transition();
363
-
done();
364
302
}
365
303
```
366
304
@@ -395,7 +333,7 @@ metadata: {
395
333
supportedActions: ["validEmail", "invalidEmail"]
396
334
},
397
335
398
-
invoke: (context, done) => {
336
+
invoke:async(context) => {
399
337
// code to get component property values and validate email goes here
400
338
...
401
339
// Get composite bag entity object (cbe), create bag item object, update bag item in cbe
@@ -404,7 +342,6 @@ invoke: (context, done) => {
404
342
context.setVariable(variableName, cbe);
405
343
context.transition("validEmail");
406
344
context.keepTurn(true);
407
-
done();
408
345
}
409
346
```
410
347
> **Tip**: When working with composite bag entities, [entity event handlers](https://github.com/oracle/bots-node-sdk/blob/master/ENTITY_EVENT_HANDLER.md) are easier to use than custom components.
@@ -421,7 +358,7 @@ The payload can be a string or a rich message object. See [Conversation Messagin
421
358
This code sample keeps showing the user a random quote of the day until the user indicates they want to quit.
Copy file name to clipboardExpand all lines: RELEASE_NOTES.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,6 @@
1
1
# Release Notes
2
2
3
+
-[Version 2.6.1](#v261)
3
4
-[Version 2.6.0](#v260)
4
5
-[Version 2.5.5](#v255)
5
6
-[Version 2.5.4](#v254)
@@ -10,6 +11,17 @@
10
11
-[Version 2.4.3](#v243)
11
12
-[Version 2.4.2](#v242)
12
13
14
+
## Version 2.6.1 <aname="v261">
15
+
16
+
### New Features
17
+
18
+
-**Support for code completion in Visual Studio Code**: When using a JavaScript-based component package, you now get code insight and code completion on newly created component services when using Visual Studio Code as your editor.
19
+
-**Improved custom component scaffolding**: Custom components created with the CLI now use the `async` syntax rather than the deprecated `done` callback.
0 commit comments