Skip to content

Commit 027a795

Browse files
jgansemangermanattanasio
authored andcommitted
Adding docs about minimum_confidence (Fix #104) (#132)
* add error checks in fb bot example * Add error checks in slack bot example * Add error checks to twilio bot example * handle unknown/badly formed messages * whoops typo fix * whoops typo fix * whoops typo fix * whoops typo fix * safer to check for error field first * safer to check for error field first * safer to check for error field first * safer to check for error field first * in case of error reply with actual error message * in case of error reply with actual error message * in case of error reply with actual error message * check only for presence of output field * check only for presence of output field * check only for presence of output fields * upd error message, check for output as field only * more docs about how to use minimum_confidence * Update README.md
1 parent e29b002 commit 027a795

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,36 @@ var receiveMiddleware = function (bot, message, next) {
128128
slackController.middleware.receive.use(receiveMiddleware);
129129
```
130130

131+
### Minimum Confidence
132+
133+
To use the setup parameter `minimum_confidence`, you have multiple options:
134+
135+
#### Use it manually in your self-defined controller.hears() function(s)
136+
137+
For example:
138+
```js
139+
controller.hears(['.*'], ['direct_message', 'direct_mention', 'mention', 'message_received'], function(bot, message) {
140+
if (message.watsonError) {
141+
bot.reply(message, "Sorry, there are technical problems."); // deal with watson error
142+
} else {
143+
if (message.watsonData.intents.length == 0) {
144+
bot.reply(message, "Sorry, I could not understand the message."); // was any intent recognized?
145+
} else if (message.watsonData.intents[0].confidence < watsonMiddleware.minimum_confidence) {
146+
bot.reply(message, "Sorry, I am not sure what you have said."); // is the confidence high enough?
147+
} else {
148+
bot.reply(message, message.watsonData.output.text.join('\n')); // reply with Watson response
149+
}
150+
}
151+
});
152+
```
153+
154+
#### Use the middleware's hear() function
155+
You can find the default implementation of this function [here](https://github.com/watson-developer-cloud/botkit-middleware/blob/e29b002f2a004f6df57ddf240a3fdf8cb28f95d0/lib/middleware/index.js#L40). If you want, you can redefine this function in the same way that watsonMiddleware.before and watsonMiddleware.after can be redefined. Refer to the [Botkit Middleware documentation](https://github.com/howdyai/botkit/blob/master/docs/middleware.md#hear-middleware) for an example. Then, to use this function instead of Botkit's default pattern matcher (that does not use minimum_confidence), plug it in using:
156+
```js
157+
controller.changeEars(watsonMiddleware.hear)
158+
```
159+
160+
Note: if you want your own `hear()` function to implement pattern matching like Botkit's default one, you will likely need to implement that yourself. Botkit's default set of 'ears' is the `hears_regexp` function which is implemented [here](https://github.com/howdyai/botkit/blob/77b7d7f80c46d5c8194453667d22118b7850e252/lib/CoreBot.js#L1180).
131161

132162
### Implementing app actions
133163

0 commit comments

Comments
 (0)