Skip to content

Commit

Permalink
[Node] Update to botbuilder 3.7.0 (microsoft#50)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
pcostantini authored Mar 1, 2017
1 parent 3e420ef commit 28d163e
Show file tree
Hide file tree
Showing 22 changed files with 39 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Node/cards-CarouselCards/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion Node/cards-RichCards/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion Node/core-AppInsights/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion Node/core-ChannelData/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion Node/core-CreateNewConversation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion Node/core-CustomState/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion Node/core-DirectLine/DirectLineBot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
6 changes: 3 additions & 3 deletions Node/core-GetConversationMembers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
17 changes: 9 additions & 8 deletions Node/core-GetConversationMembers/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion Node/core-GetConversationMembers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion Node/core-MultiDialogs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion Node/core-ReceiveAttachment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions Node/core-SendAttachment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions Node/core-SendAttachment/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion Node/core-SendAttachment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion Node/core-State/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion Node/demo-ContosoFlowers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion Node/demo-Search/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion Node/intelligence-ImageCaption/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion Node/intelligence-LUIS/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion Node/intelligence-SimilarProducts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion Node/intelligence-SpeechToText/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 28d163e

Please sign in to comment.