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
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,11 +48,11 @@ module.exports = {
48
48
}
49
49
}
50
50
```
51
-
The old style of defining the `invoke` function using the `done` callback argument is still supported:
51
+
The old style of defining the `invoke` function using the `done` callback argument is still supported (with `conversation` as the old name for the `context` argument):
52
52
53
53
```javascript
54
-
invoke: (context, done) => {
55
-
context.reply('hello world');
54
+
invoke: (conversation, done) => {
55
+
conversation.reply('hello world');
56
56
done();
57
57
}
58
58
}
@@ -64,7 +64,7 @@ In addition, you no longer have to remember to call `done()` at every place in y
64
64
65
65
When using typescript, the custom component class should implement the `CustomComponent` interface which requires two methods to be present:
66
66
- the `metadata` method that should return an object of type `CustomComponentMetadata`.
67
-
- the `invoke` method that should accept two arguments, the context of type `CustomComponentContext` and a callback of type `InvocationCallback`.
67
+
- the `invoke` method that should accept one argument, the context of type `CustomComponentContext`.
Copy file name to clipboardExpand all lines: ENTITY_EVENT_HANDLER.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@
21
21
22
22
An entity event handler (EEH) works in concert with a `System.ResolveEntities` (RE) or `System.CommonResponse` (CRC) component that is defined in the YAML dialog flow to resolve a composite bag entity. An EEH is deployed in a custom component service, in the same way as a custom component, but does not have its own state in the YAML. The RE or CRC component identifies a series of events which you can write event handlers for in an EEH component. Whenever such an event occurs, the RE or CRC component will check whether an EEH is registered with the composite bag entity, and whether the EEH has a handler defined for this specific event. If this is the case, the RE or CRC component will invoke the event handler method in the EEH.
23
23
24
-
This event-driven approach makes it much easier for a developer to execute the right code at the right moment while resolving the composite bag entity. Furthermore, it provides full control over the bot messages that are sent to the user, any "candidate" message generated by CRC or RE can always be replaced by writing a corresponding event handler.
24
+
This event-driven approach makes it much easier for you to execute the right code at the right moment while resolving the composite bag entity. Furthermore, it provides full control over the bot messages that are sent to the user, any "candidate" message generated by CRC or RE can always be replaced by writing a corresponding event handler.
25
25
26
26
While freemarker expressions can still be used in the various fields of a composite bag item, you can choose to avoid writing any freemarker expressions by including the appropriate handlers in his EEH using Javascript.
27
27
@@ -103,9 +103,9 @@ export class MyEntityEventHandler implements EntityEventHandler {
The first argument of each event method is the `event` object. The properties available in this object depend on the type of event.
106
-
See the list of supported entity events for information pn which properties are available with which event.
106
+
See the list of supported entity events for information on which properties are available with which event.
107
107
108
-
The second argument each event method is the `context` object. This object references the [EntityResolutionContext](https://oracle.github.io/bots-node-sdk/EntityResolutionContext.html) that provides access to many convenience methods to create your event handler logic.
108
+
The second argument of each event method is the `context` object. This object references the [EntityResolutionContext](https://oracle.github.io/bots-node-sdk/EntityResolutionContext.html) that provides access to many convenience methods to create your event handler logic.
109
109
110
110
More information on creating conversation messages from an event handler can be found [here](https://github.com/oracle/bots-node-sdk/blob/master/MESSAGE_MODEL.md).
111
111
@@ -128,7 +128,7 @@ The table below lists all entity level events currently supported:
128
128
129
129
| Event | Description | Event Properties |
130
130
|--|--|--|
131
-
| validate | Handler for entity-level validations that include two or more bag item values. Validation errors can be registered by calling context.addValidationError(itemName,errorMessage). If validation should fail, this handler should return false. if validation fails, NONE of the item values provided by the user in the last user message will be updated.<br/><br/>NOTE: This handler is called when at least one bag item value has changed. | <ul><li><b>newValues</b>: JSONObject with key-value pairs where key is the item name and value the new item value.</li><li><b>oldValues</b>: JSONObject with key-value pairs where key is the item name and value the old item value.</li><li><b>currentItem</b>: name of item currently being resolved.</li></ul>
131
+
| validate | Handler for entity-level validations that include two or more bag item values. Validation errors can be registered by calling `context.addValidationError(itemName,errorMessage)`. If validation should fail, this handler should return false. if validation fails, NONE of the item values provided by the user in the last user message will be updated.<br/><br/>NOTE: This handler is called when at least one bag item value has changed. | <ul><li><b>newValues</b>: JSONObject with key-value pairs where key is the item name and value the new item value.</li><li><b>oldValues</b>: JSONObject with key-value pairs where key is the item name and value the old item value.</li><li><b>currentItem</b>: name of item currently being resolved.</li></ul>
132
132
| publishMessage | Generic fallback handler that is called when item-specific prompt or disambiguate handler is not specified. | <ul><li><b>currentItem</b>: name of item currently being resolved.</li><li><b>promptCount</b>: number of times the user is prompted for current item (only set in case of prompt event).</li><li><b>disambiguationValues</b>: list of values that matches the user input (only set in case of disambiguate event).</li></ul>
133
133
| maxPromptsReached | Generic fallback handler when item-specific handler for reaching max prompts is not specified. | <ul><li><b>currentItem</b>: name of item currently being resolved.</li><li><b>promptCount</b>: number of times the user is prompted for current item (only set in case of prompt event).</li></ul>
134
134
| resolved | Function that gets called when the composite bag entity is resolved. You will typically use this function to call some backend API to complete the transaction which the composite bag entity collected the data for. If the backend API call return some errors, possibly forcing you to re-prompt for some invalid bag items, you can do so by simply clearing those bag items. The RE/CRC component will notice the entity is not fully resolved after all, and will resume prompting for missing bag items. | none
@@ -148,7 +148,7 @@ The table below lists all entity-item level events currently supported:
148
148
149
149
## Code Samples <aname="samples">
150
150
151
-
The samples below use an Expense composite bag entity, which has the following items:
151
+
The samples below use an `Expense` composite bag entity, which has the following items:
152
152
153
153
| Name | Type | Entity Name |
154
154
|--|--|--|
@@ -158,7 +158,7 @@ The samples below use an Expense composite bag entity, which has the following i
158
158
| Type | Entity | ExpenseType
159
159
160
160
### How to conditionally prompt for an item <aname="prompt">
161
-
We only want to prompt for a receipt when the expense amount is greater than 25 dollars. This can be achieved by adding the shouldPrompt event handler for an item
161
+
We only want to prompt for a receipt when the expense amount is greater than 25 dollars. This can be achieved by adding the `shouldPrompt` event handler for an item
162
162
163
163
```javascript
164
164
items: {
@@ -169,7 +169,7 @@ items: {
169
169
}
170
170
```
171
171
172
-
Note here that the Amount item returns a CURRENCY JSON object, and amount property inside this object holds the amount value.
172
+
Note here that the `Amount` item returns a `CURRENCY` JSON object, and `amount` property inside this object holds the amount value.
173
173
174
174
### How to validate an item <a name="validate">
175
175
Here is the event handler to enforce the expense amount is at least 5:
@@ -186,7 +186,7 @@ items: {
186
186
}
187
187
```
188
188
189
-
Note how we obtain the new value from the validation event object. And since the Amount item value is a CURRENCY JSON object, we need to obtain the amount property from it. We use the `addValidationError` function to register the error message . We could also have used `conversation.reply()` directly. The difference is that when using `conversation.reply()` further processing in the RE/CRC component is stopped, so other items that just got a value are not validated.
189
+
Note how we obtain the new value from the validation event object. And since the `Amount` item value is a CURRENCY JSON object, we need to obtain the `amount` property from it. We use the `addValidationError` function to register the error message . We could also have used `conversation.reply()` directly. The difference is that when using `conversation.reply()` further processing in the RE/CRC component is stopped, so other items that just got a value are not validated.
190
190
191
191
To read the validation error message from the skill resource bundle, instead of hardcoding the text, the translate function can be used:
Copy file name to clipboardExpand all lines: README.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@ This section explains the basic CLI commands to get your component service up an
31
31
bots-node-sdk init MyComponentService
32
32
```
33
33
34
-
This creates a new commponent service named `MyComponentService` in a directory by the same name.
34
+
This creates a new component service named `MyComponentService` in a directory by the same name.
35
35
The component service includes one sample custom component named `helloWorld`.
36
36
37
37
### Adding a Custom Component to Existing Service
@@ -103,12 +103,12 @@ See the README.md created in your scaffolded typescript project for more informa
103
103
<!--[nodoc]-->
104
104
-[Using the CLI](https://github.com/oracle/bots-node-sdk/blob/master/bin/CLI.md) - Command line capabilities to facilitate writing custom components and entity event handlers.
105
105
-[Writing Custom Components](https://github.com/oracle/bots-node-sdk/blob/master/CUSTOM_COMPONENT.md) - Guidelines and tips for writing custom components.
106
-
-[Writing Entity Event Handlers](https://github.com/oracle/bots-node-sdk/blob/master/ENTIY_EVENT_HANDLER.md) - Guidelines and tips for writing entity event handlers.
107
-
-[Conversation Messaging](https://github.com/oracle/bots-node-sdk/blob/master/MESSAGE_MODEL.md) - Creating conversation messages from custom code
106
+
-[Writing Entity Event Handlers](https://github.com/oracle/bots-node-sdk/blob/master/ENTITY_EVENT_HANDLER.md) - Guidelines and tips for writing entity event handlers.
107
+
-[Conversation Messaging](https://github.com/oracle/bots-node-sdk/blob/master/MESSAGE_MODEL.md) - Creating conversation messages from custom code.
108
108
-[Writing Webhooks](https://github.com/oracle/bots-node-sdk/blob/master/WEBHOOK.md) - Integrate with custom messaging channels using incoming/outgoing webhook.
109
109
-[Unit Testing](https://github.com/oracle/bots-node-sdk/blob/master/testing/TESTING.md) - Unit testing facilities.
110
110
-[Documentation](https://oracle.github.io/bots-node-sdk) - Full SDK documentation.
111
-
-[Release Notes](https://github.com/oracle/bots-node-sdk/blob/master/RELEASE_NOTES.md) - List of new features and fixed issues for each release
111
+
-[Release Notes](https://github.com/oracle/bots-node-sdk/blob/master/RELEASE_NOTES.md) - List of new features and fixed issues for each release.
This command will create a _new_ custom component or event handler within an **existing** component
81
-
package, and write to the `<dest>` output path. If the output path is not specified, the component will be written to the `components` directory or `src\components` directory when using typesript. If this directory doesn't exist it will be created.
80
+
package, and write to the `<dest>` output path. If the output path is not specified, the component will be written to the `components` directory or `src\components` directory when using typescript. If this directory doesn't exist it will be created.
82
81
The component `<name>` and `<type>` are required and `<type>` should be set to `[c]ustom` or `[e]ntityEventHandler`.
83
82
84
83
For example, to create a new entity event handler component named `resolvePizza`, you can use the following command:
@@ -104,9 +103,7 @@ A node supervisor may also be used in the same way.
104
103
105
104
### 4. Package for Deployment: `pack [options]`
106
105
107
-
Most often, custom implementations can be packaged with `npm pack` or `zip`
108
-
depending on the deployment target. The `pack` command here is intended to
109
-
provide validation and convenience methods for creating a deployable artifact.
106
+
The `npm pack` command can be used to package the component service as a `.tgz` file that can be uploaded to the ODA embedded container.
0 commit comments