Skip to content

Commit 508b040

Browse files
committed
[docs] Add example of updateContext to readme
1 parent 955adff commit 508b040

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@ A common scenario of processing actions is:
220220

221221
### Using sendToWatson to update context
222222

223-
Using sendToWatson to update context simplifies the bot code compared to solution using updateContext below.
224-
225223
```js
226224
const checkBalance = async (context) => {
227225
//do something real here
@@ -258,6 +256,20 @@ const processWatsonResponse = async (bot, message) => {
258256
controller.on('message_received', processWatsonResponse);
259257
```
260258

259+
### Using updateContext to update context
260+
261+
sendToWatson should cover majority of use cases,
262+
but updateContext method can be useful when you want to update context from bot code,
263+
but there is no need to make a special request to Watson.
264+
265+
```js
266+
if (params.amount) {
267+
const context = message.watsonData.context;
268+
context.paymentAmount = params.amount;
269+
await watsonMiddleware.updateContext(message.user, context);
270+
}
271+
```
272+
261273
## Implementing event handlers
262274

263275
Events are messages having type different than `message`.

0 commit comments

Comments
 (0)