Skip to content

Commit

Permalink
Handling API Operation error when Channel does not support it
Browse files Browse the repository at this point in the history
  • Loading branch information
pcostantini committed Sep 30, 2016
1 parent 0afde12 commit f8aaf87
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 4 additions & 2 deletions Node/core-CreateNewConversation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ The minimum prerequisites to run this sample are:

### Code Highlights

Bot Builder uses dialogs to model a conversational process, the exchange of messages, between bot and user. [bot.beginDialog()](app.js#L28) can be used to proactively start a new dialog to interact with the user.
Bot Builder uses dialogs to model a conversational process, the exchange of messages, between bot and user. [bot.beginDialog()](app.js#L32) can be used to proactively start a new dialog to interact with the user.
Because, an address is required to initiate a new conversation, this user address should be saved during any previous conversation with the user.
Any current conversation between the bot and user will be replaced with a new dialog stack.
Alternatively, [bot.send()](https://docs.botframework.com/en-us/node/builder/chat-reference/classes/_botbuilder_d_.universalbot.html#send) can be used to send a message without starting a dialog.

````JavaScript
// this is the object we should persist if we want to create a new conversation anytime later
// this is the object we should persist if we want to create a new conversation anytime later
// copy it without the conversationId
var address = session.message.address;
delete address.conversation;

// then... on another scope

Expand Down
15 changes: 13 additions & 2 deletions Node/core-CreateNewConversation/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,19 @@ setInterval(function () {

console.log('Starting survey for address:', address);

// start survey dialog using stored address
bot.beginDialog(address, '/survey');
// new conversation address, copy without conversationId
var newConversationAddress = Object.assign({}, address);
delete newConversationAddress.conversation;

// start survey dialog
bot.beginDialog(newConversationAddress, '/survey', null, (err) => {
if(err) {
// error ocurred while starting new conversation. Channel not supported?
bot.send(new builder.Message()
.text('This channel does not support this operation: ' + err.message)
.address(address));
}
});

});
}, 5000);
Expand Down

0 comments on commit f8aaf87

Please sign in to comment.