From 28d163ecf6d49b85c91ae108ba98202cfef330c9 Mon Sep 17 00:00:00 2001 From: Pablo Costantini Date: Wed, 1 Mar 2017 18:01:14 -0300 Subject: [PATCH] [Node] Update to botbuilder 3.7.0 (#50) * Update botbuilder dependency to 3.7.0 * GetConversationMembers error handling update * Set Connector's client scheme to the same as origin message (fixes issue when running with the Emulator) --- Node/cards-CarouselCards/package.json | 2 +- Node/cards-RichCards/package.json | 2 +- Node/core-AppInsights/package.json | 2 +- Node/core-ChannelData/package.json | 2 +- Node/core-CreateNewConversation/package.json | 2 +- Node/core-CustomState/package.json | 2 +- Node/core-DirectLine/DirectLineBot/package.json | 2 +- Node/core-GetConversationMembers/README.md | 6 +++--- Node/core-GetConversationMembers/app.js | 17 +++++++++-------- Node/core-GetConversationMembers/package.json | 2 +- Node/core-MultiDialogs/package.json | 2 +- Node/core-ReceiveAttachment/package.json | 2 +- Node/core-SendAttachment/README.md | 8 ++++---- Node/core-SendAttachment/app.js | 9 +++++---- Node/core-SendAttachment/package.json | 2 +- Node/core-State/package.json | 2 +- Node/demo-ContosoFlowers/package.json | 2 +- Node/demo-Search/package.json | 2 +- Node/intelligence-ImageCaption/package.json | 2 +- Node/intelligence-LUIS/package.json | 2 +- Node/intelligence-SimilarProducts/package.json | 2 +- Node/intelligence-SpeechToText/package.json | 2 +- 22 files changed, 39 insertions(+), 37 deletions(-) diff --git a/Node/cards-CarouselCards/package.json b/Node/cards-CarouselCards/package.json index aa37722c5a..71513964c8 100644 --- a/Node/cards-CarouselCards/package.json +++ b/Node/cards-CarouselCards/package.json @@ -21,7 +21,7 @@ "url": "https://github.com/Microsoft/BotBuilder-Samples.git" }, "dependencies": { - "botbuilder": "^3.6.0", + "botbuilder": "^3.7.0", "restify": "^4.3.0", "dotenv-extended": "^1.0.4" } diff --git a/Node/cards-RichCards/package.json b/Node/cards-RichCards/package.json index 97b45cbff0..881b2575c1 100644 --- a/Node/cards-RichCards/package.json +++ b/Node/cards-RichCards/package.json @@ -21,7 +21,7 @@ "url": "https://github.com/Microsoft/BotBuilder-Samples.git" }, "dependencies": { - "botbuilder": "^3.6.0", + "botbuilder": "^3.7.0", "restify": "^4.3.0", "dotenv-extended": "^1.0.4" } diff --git a/Node/core-AppInsights/package.json b/Node/core-AppInsights/package.json index 7dc6180025..98bf43672a 100644 --- a/Node/core-AppInsights/package.json +++ b/Node/core-AppInsights/package.json @@ -22,7 +22,7 @@ }, "dependencies": { "applicationinsights": "^0.17.2", - "botbuilder": "^3.6.0", + "botbuilder": "^3.7.0", "dotenv-extended": "^1.0.4", "restify": "^4.3.0" } diff --git a/Node/core-ChannelData/package.json b/Node/core-ChannelData/package.json index 60ea250c6a..fde6a338ce 100644 --- a/Node/core-ChannelData/package.json +++ b/Node/core-ChannelData/package.json @@ -21,7 +21,7 @@ "url": "https://github.com/Microsoft/BotBuilder-Samples.git" }, "dependencies": { - "botbuilder": "^3.6.0", + "botbuilder": "^3.7.0", "dotenv-extended": "^1.0.4", "restify": "^4.3.0" } diff --git a/Node/core-CreateNewConversation/package.json b/Node/core-CreateNewConversation/package.json index 51f26a9a62..35bd8a6e81 100644 --- a/Node/core-CreateNewConversation/package.json +++ b/Node/core-CreateNewConversation/package.json @@ -21,7 +21,7 @@ "url": "https://github.com/Microsoft/BotBuilder-Samples.git" }, "dependencies": { - "botbuilder": "^3.6.0", + "botbuilder": "^3.7.0", "restify": "^4.3.0", "dotenv-extended": "^1.0.4" } diff --git a/Node/core-CustomState/package.json b/Node/core-CustomState/package.json index 63ee7aa387..51d7a47a39 100644 --- a/Node/core-CustomState/package.json +++ b/Node/core-CustomState/package.json @@ -21,7 +21,7 @@ "url": "https://github.com/Microsoft/BotBuilder-Samples.git" }, "dependencies": { - "botbuilder": "^3.6.0", + "botbuilder": "^3.7.0", "botbuilder-azure": "^3.0.2", "dotenv-extended": "^1.0.4", "restify": "^4.3.0" diff --git a/Node/core-DirectLine/DirectLineBot/package.json b/Node/core-DirectLine/DirectLineBot/package.json index 553240874b..1bc6c97ee7 100644 --- a/Node/core-DirectLine/DirectLineBot/package.json +++ b/Node/core-DirectLine/DirectLineBot/package.json @@ -21,7 +21,7 @@ "url": "https://github.com/Microsoft/BotBuilder-Samples.git" }, "dependencies": { - "botbuilder": "^3.6.0", + "botbuilder": "^3.7.0", "dotenv-extended": "^1.0.4", "restify": "^4.3.0" } diff --git a/Node/core-GetConversationMembers/README.md b/Node/core-GetConversationMembers/README.md index 36ce435526..16142c7326 100644 --- a/Node/core-GetConversationMembers/README.md +++ b/Node/core-GetConversationMembers/README.md @@ -63,13 +63,13 @@ var connectorApiClient = new Swagger({ }); ```` -Once a message is received in a group conversation, we'll ask the API for its members. In order to call the REST API, we need to be authenticated using the bot's JWT token (see [app.js - addTokenToClient function](app.js#L85-95)) and then override the API's hostname using the channel's serviceUrl (see [app.js - client.setHost](app.js#L41-L43)). -Then we call Swagger generated client (`client.Conversations.Conversations_GetConversationMembers`) and pass the response to a helper function that will print the members list to the conversation ([app.js - printMembersInChannel function](app.js#L97-L108)). +Once a message is received in a group conversation, we'll ask the API for its members. In order to call the REST API, we need to be authenticated using the bot's JWT token (see [app.js - addTokenToClient function](app.js#L86-96)) and then override the API's hostname using the channel's serviceUrl (see [app.js - client.setHost](app.js#L41-L45)). +Then we call Swagger generated client (`client.Conversations.Conversations_GetConversationMembers`) and pass the response to a helper function that will print the members list to the conversation ([app.js - printMembersInChannel function](app.js#L98-L109)). ````JavaScript // Helper methods -// Inject the conenctor's JWT token into to the Swagger client +// Inject the connector's JWT token into to the Swagger client function addTokenToClient(connector, clientPromise) { // ask the connector for the token. If it expired, a new token will be requested to the API var obtainToken = Promise.promisify(connector.getAccessToken.bind(connector)); diff --git a/Node/core-GetConversationMembers/app.js b/Node/core-GetConversationMembers/app.js index 34f89f49d3..1cf9519972 100644 --- a/Node/core-GetConversationMembers/app.js +++ b/Node/core-GetConversationMembers/app.js @@ -38,17 +38,18 @@ var bot = new builder.UniversalBot(connector, function (session) { // 1. inject the JWT from the connector to the client on every call addTokenToClient(connector, connectorApiClient).then(function (client) { - // 2. override API client host (api.botframework.com) with channel's serviceHost (e.g.: slack.botframework.com) - var serviceHost = url.parse(message.address.serviceUrl).host; - client.setHost(serviceHost); + // 2. override API client host and schema (https://api.botframework.com) with channel's serviceHost (e.g.: https://slack.botframework.com or http://localhost:NNNN) + var serviceUrl = url.parse(message.address.serviceUrl); + var serviceScheme = serviceUrl.protocol.split(':')[0]; + client.setSchemes([serviceScheme]); + client.setHost(serviceUrl.host); // 3. GET /v3/conversations/{conversationId}/members - client.Conversations.Conversations_GetConversationMembers({ conversationId: conversationId }) + return client.Conversations.Conversations_GetConversationMembers({ conversationId: conversationId }) .then(function (res) { printMembersInChannel(message.address, res.obj); - }) - .catch(function (error) { - console.log('Error retrieving conversation members: ' + error.statusText); }); + }).catch(function (error) { + console.log('Error retrieving conversation members', error); }); }); @@ -82,7 +83,7 @@ bot.on('conversationUpdate', function (message) { // Helper methods -// Inject the conenctor's JWT token into to the Swagger client +// Inject the connector's JWT token into to the Swagger client function addTokenToClient(connector, clientPromise) { // ask the connector for the token. If it expired, a new token will be requested to the API var obtainToken = Promise.promisify(connector.getAccessToken.bind(connector)); diff --git a/Node/core-GetConversationMembers/package.json b/Node/core-GetConversationMembers/package.json index adec822c1b..6bfe17c8a8 100644 --- a/Node/core-GetConversationMembers/package.json +++ b/Node/core-GetConversationMembers/package.json @@ -22,7 +22,7 @@ }, "dependencies": { "bluebird": "^3.4.7", - "botbuilder": "^3.6.0", + "botbuilder": "^3.7.0", "restify": "^4.3.0", "swagger-client": "^2.1.26", "dotenv-extended": "^1.0.4" diff --git a/Node/core-MultiDialogs/package.json b/Node/core-MultiDialogs/package.json index dd8990eedf..b555a4a1d1 100644 --- a/Node/core-MultiDialogs/package.json +++ b/Node/core-MultiDialogs/package.json @@ -22,7 +22,7 @@ }, "dependencies": { "bluebird": "^3.4.7", - "botbuilder": "^3.6.0", + "botbuilder": "^3.7.0", "restify": "^4.3.0", "dotenv-extended": "^1.0.4" } diff --git a/Node/core-ReceiveAttachment/package.json b/Node/core-ReceiveAttachment/package.json index 632264a22a..616e592b50 100644 --- a/Node/core-ReceiveAttachment/package.json +++ b/Node/core-ReceiveAttachment/package.json @@ -22,7 +22,7 @@ }, "dependencies": { "bluebird": "^3.4.7", - "botbuilder": "^3.6.0", + "botbuilder": "^3.7.0", "request": "^2.79.0", "request-promise": "^4.1.1", "restify": "^4.3.0", diff --git a/Node/core-SendAttachment/README.md b/Node/core-SendAttachment/README.md index eadfbd0120..c88c0b69a6 100644 --- a/Node/core-SendAttachment/README.md +++ b/Node/core-SendAttachment/README.md @@ -59,11 +59,11 @@ It does require a few more steps than the other methods, but leverages the chann 0. Read (or generate) the content file and store it in a Buffer for encoding to base64 ([relevant code](./app.js#L131)) 1. Create a client to the Connector API ([relevant code](./app.js#L12-L17)) 2. Inject the Bot Connector's token into the Connector API client ([relevant code](./app.js#L151)) -3. Set the Connector API client service url to the Connector's ([relevant code](./app.js#L152-L155)) -4. Upload the base64 encoded payload to the conversations/attachments endpoint ([relevant code](./app.js#L157-L167)) -5. Use the returned attachmentId to generate the contentUrl ([relevant code](./app.js#L169-L173)) +3. Set the Connector API client service url to the Connector's ([relevant code](./app.js#L152-L156)) +4. Upload the base64 encoded payload to the conversations/attachments endpoint ([relevant code](./app.js#L158-L168)) +5. Use the returned attachmentId to generate the contentUrl ([relevant code](./app.js#L170-L174)) -This sample provides a [helper method](./app.js#L128-L176) you can use that encapsulates most of the previous steps. +This sample provides a [helper method](./app.js#L128-L177) you can use that encapsulates most of the previous steps. ````JavaScript // read file content and upload diff --git a/Node/core-SendAttachment/app.js b/Node/core-SendAttachment/app.js index 5694bcad0b..d07c41686a 100644 --- a/Node/core-SendAttachment/app.js +++ b/Node/core-SendAttachment/app.js @@ -130,7 +130,7 @@ function uploadAttachment(fileData, contentType, fileName, connector, connectorA var base64 = Buffer.from(fileData).toString('base64'); - // Inject the conenctor's JWT token into to the Swagger client + // Inject the connector's JWT token into to the Swagger client function addTokenToClient(connector, clientPromise) { // ask the connector for the token. If it expired, a new token will be requested to the API var obtainToken = Promise.promisify(connector.addAccessToken.bind(connector)); @@ -149,10 +149,11 @@ function uploadAttachment(fileData, contentType, fileName, connector, connectorA // 1. inject the JWT from the connector to the client on every call return addTokenToClient(connector, connectorApiClient).then(function (client) { - // 2. override API client host (api.botframework.com) with channel's serviceHost (e.g.: slack.botframework.com) + // 2. override API client host and schema (https://api.botframework.com) with channel's serviceHost (e.g.: https://slack.botframework.com or http://localhost:NNNN) var serviceUrl = url.parse(baseServiceUrl); - var serviceHost = serviceUrl.host; - client.setHost(serviceHost); + var serviceScheme = serviceUrl.protocol.split(':')[0]; + client.setSchemes([serviceScheme]); + client.setHost(serviceUrl.host); // 3. POST /v3/conversations/{conversationId}/attachments var uploadParameters = { diff --git a/Node/core-SendAttachment/package.json b/Node/core-SendAttachment/package.json index b77745aa18..4cb718a1dd 100644 --- a/Node/core-SendAttachment/package.json +++ b/Node/core-SendAttachment/package.json @@ -22,7 +22,7 @@ }, "dependencies": { "bluebird": "^3.4.7", - "botbuilder": "^3.6.0", + "botbuilder": "^3.7.0", "restify": "^4.3.0", "swagger-client": "^2.1.32", "dotenv-extended": "^1.0.4" diff --git a/Node/core-State/package.json b/Node/core-State/package.json index 58dee9ee3c..f85133f23b 100644 --- a/Node/core-State/package.json +++ b/Node/core-State/package.json @@ -21,7 +21,7 @@ "url": "https://github.com/Microsoft/BotBuilder-Samples.git" }, "dependencies": { - "botbuilder": "^3.6.0", + "botbuilder": "^3.7.0", "restify": "^4.3.0", "dotenv-extended": "^1.0.4" } diff --git a/Node/demo-ContosoFlowers/package.json b/Node/demo-ContosoFlowers/package.json index b6c895d88d..f293d0f171 100644 --- a/Node/demo-ContosoFlowers/package.json +++ b/Node/demo-ContosoFlowers/package.json @@ -23,7 +23,7 @@ "dependencies": { "bluebird": "^3.4.7", "body-parser": "^1.15.2", - "botbuilder": "^3.6.0", + "botbuilder": "^3.7.0", "botbuilder-location": "^1.0.3", "express": "^4.14.0", "geobing": "^0.1.3", diff --git a/Node/demo-Search/package.json b/Node/demo-Search/package.json index f21fbb4e1b..5b867eb85d 100644 --- a/Node/demo-Search/package.json +++ b/Node/demo-Search/package.json @@ -22,7 +22,7 @@ }, "dependencies": { "bluebird": "^3.4.7", - "botbuilder": "^3.6.0", + "botbuilder": "^3.7.0", "lodash": "^4.17.4", "lorem-ipsum": "^1.0.3", "node-uuid": "^1.4.7", diff --git a/Node/intelligence-ImageCaption/package.json b/Node/intelligence-ImageCaption/package.json index 1513469560..daf2bf0229 100644 --- a/Node/intelligence-ImageCaption/package.json +++ b/Node/intelligence-ImageCaption/package.json @@ -21,7 +21,7 @@ "url": "https://github.com/Microsoft/BotBuilder-Samples.git" }, "dependencies": { - "botbuilder": "^3.6.0", + "botbuilder": "^3.7.0", "dotenv-extended": "^1.0.4", "needle": "^1.4.3", "request": "^2.79.0", diff --git a/Node/intelligence-LUIS/package.json b/Node/intelligence-LUIS/package.json index 5f1f817e5c..65bd0db91e 100644 --- a/Node/intelligence-LUIS/package.json +++ b/Node/intelligence-LUIS/package.json @@ -22,7 +22,7 @@ }, "dependencies": { "bluebird": "^3.4.7", - "botbuilder": "^3.6.0", + "botbuilder": "^3.7.0", "dotenv-extended": "^1.0.4", "request": "^2.79.0", "restify": "^4.3.0" diff --git a/Node/intelligence-SimilarProducts/package.json b/Node/intelligence-SimilarProducts/package.json index e41f96c7f5..849153d5a2 100644 --- a/Node/intelligence-SimilarProducts/package.json +++ b/Node/intelligence-SimilarProducts/package.json @@ -8,7 +8,7 @@ "author": "Microsoft Corp.", "license": "MIT", "dependencies": { - "botbuilder": "^3.6.0", + "botbuilder": "^3.7.0", "dotenv-extended": "^1.0.4", "request": "^2.79.0", "restify": "^4.3.0", diff --git a/Node/intelligence-SpeechToText/package.json b/Node/intelligence-SpeechToText/package.json index 7682ff7a89..db3177f84d 100644 --- a/Node/intelligence-SpeechToText/package.json +++ b/Node/intelligence-SpeechToText/package.json @@ -21,7 +21,7 @@ "url": "https://github.com/Microsoft/BotBuilder-Samples.git" }, "dependencies": { - "botbuilder": "^3.6.0", + "botbuilder": "^3.7.0", "dotenv-extended": "^1.0.4", "needle": "^1.4.3", "node-uuid": "^1.4.7",