Skip to content

Commit

Permalink
Apply fixes to samples after testing
Browse files Browse the repository at this point in the history
- Fix on GetConversationMembers to work on one-on-one conversations (Node)
- Store full address on CreateNewConversation
- Print message if has text on DirectLine (Node)
- Fallback username for Telegram on ContosoFlowers
- Fix azuredeploy.json for Search (C#)
- azuredeploy option for selecting which Search Bot to deploy (Node)
  • Loading branch information
JuanAr authored and pcostantini committed Sep 23, 2016
1 parent 86ebba0 commit 24e9d5a
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 273 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private async Task OnOptionSelected(IDialogContext context, IAwaitable<IMessageA
if (message.Text == Resources.RootDialog_Welcome_Orders)
{
this.order = new Models.Order();
var addressDialog = this.dialogFactory.Create<AddressDialog, string>(string.Format(CultureInfo.CurrentCulture, Resources.RootDialog_DeliveryAddress_Prompt, message.From.Name));
var addressDialog = this.dialogFactory.Create<AddressDialog, string>(string.Format(CultureInfo.CurrentCulture, Resources.RootDialog_DeliveryAddress_Prompt, message.From.Name ?? "User"));
context.Call(addressDialog, this.AfterDeliveryAddress);
}
else if (message.Text == Resources.RootDialog_Welcome_Support)
Expand Down
16 changes: 0 additions & 16 deletions CSharp/demo-Search/JobListingBot/azuredeploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,6 @@
},
"MicrosoftAppPassword": {
"type": "string"
},
"SearchDialogsServiceName": {
"type": "string",
"defaultValue": "azs-playground"
},
"SearchDialogsServiceKey": {
"type": "string",
"defaultValue": "512C4FBA9EED64A31A1052CFE3F7D3DB"
},
"SearchDialogsIndexName": {
"type": "string",
"defaultValue": "nycjobs"
}
},
"resources": [
Expand Down Expand Up @@ -109,10 +97,6 @@
{
"name": "MicrosoftAppPassword",
"value": "[parameters('MicrosoftAppPassword')]"
},
{
"name": "MicrosoftBingMapsKey",
"value": "[parameters('MicrosoftBingMapsKey')]"
}
]
}
Expand Down
16 changes: 0 additions & 16 deletions CSharp/demo-Search/RealEstateBot/azuredeploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,6 @@
},
"MicrosoftAppPassword": {
"type": "string"
},
"SearchDialogsServiceName": {
"type": "string",
"defaultValue": "realestate"
},
"SearchDialogsServiceKey": {
"type": "string",
"defaultValue": "82BCF03D2FC9AC7F4E9D7DE1DF3618A5"
},
"SearchDialogsIndexName": {
"type": "string",
"defaultValue": "listings"
}
},
"resources": [
Expand Down Expand Up @@ -109,10 +97,6 @@
{
"name": "MicrosoftAppPassword",
"value": "[parameters('MicrosoftAppPassword')]"
},
{
"name": "MicrosoftBingMapsKey",
"value": "[parameters('MicrosoftBingMapsKey')]"
}
]
}
Expand Down
11 changes: 2 additions & 9 deletions Node/core-CreateNewConversation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,8 @@ Any current conversation between the bot and user will be replaced with a new di
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
// minimal information copied from the address of a previous message
// this is the obj we should persist if we want to create a new conversation anytime later
var address = {
channelId: msg.address.channelId,
serviceUrl: msg.address.serviceUrl,
user: msg.address.user,
bot: msg.address.bot,
useAuth: true
};
// this is the object we should persist if we want to create a new conversation anytime later
var address = session.message.address;

// then... on another scope

Expand Down
13 changes: 1 addition & 12 deletions Node/core-CreateNewConversation/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,7 @@ bot.dialog('/', function (session) {
var msg = session.message;

// store user's address

// minimal information copied from the address of a previous message
// we should persist this object if we want to create a new conversation anytime later
var address = {
channelId: msg.address.channelId,
serviceUrl: msg.address.serviceUrl,
user: msg.address.user,
bot: msg.address.bot,
useAuth: true
};

// store address
var address = msg.address;
userStore.push(address);

// end current dialog
Expand Down
5 changes: 4 additions & 1 deletion Node/core-DirectLine/DirectLineClient/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ function printMessages(messages) {
}

function printMessage(message) {
console.log(message.text);
if(message.text) {
console.log(message.text);
}

if (message.channelData) {
switch (message.channelData.contentType) {
case "application/vnd.microsoft.card.hero":
Expand Down
87 changes: 42 additions & 45 deletions Node/core-GetConversationMembers/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,57 +27,52 @@ var connectorApiClient = new Swagger(


bot.on('conversationUpdate', function (message) {
if (message.address.conversation.isGroup) {

if (message.membersAdded) {
var membersAdded = message.membersAdded
.map((m) => {
var isSelf = m.id === message.address.bot.id;
return (isSelf ? message.address.bot.name : m.name) + ' (Id: ' + m.id + ')';
})
.join(', ');

var reply = new builder.Message()
.address(message.address)
.text('Welcome ' + membersAdded);
bot.send(reply);
}

if (message.membersRemoved) {
var membersRemoved = message.membersRemoved
.map((m) => {
var isSelf = m.id === message.address.bot.id;
return (isSelf ? message.address.bot.name : m.name) + ' (Id: ' + m.id + ')';
})
.join(', ');
if (message.membersAdded && message.membersAdded.length > 0) {
var membersAdded = message.membersAdded
.map((m) => {
var isSelf = m.id === message.address.bot.id;
return (isSelf ? message.address.bot.name : m.name) || '' + ' (Id: ' + m.id + ')';
})
.join(', ');

var reply = new builder.Message()
.address(message.address)
.text('Welcome ' + membersAdded);
bot.send(reply);
}

var reply = new builder.Message()
.address(message.address)
.text('The following members ' + membersRemoved + ' were removed or left the conversation :(');
bot.send(reply);
}
if (message.membersRemoved && message.membersRemoved.length > 0) {
var membersRemoved = message.membersRemoved
.map((m) => {
var isSelf = m.id === message.address.bot.id;
return (isSelf ? message.address.bot.name : m.name) || '' + ' (Id: ' + m.id + ')';
})
.join(', ');

var reply = new builder.Message()
.address(message.address)
.text('The following members ' + membersRemoved + ' were removed or left the conversation :(');
bot.send(reply);
}
});

bot.dialog('/', function (session) {
var message = session.message;
if (message.address.conversation.isGroup) {
var conversationId = message.address.conversation.id;

// when a group conversation message is recieved,
// get the conversation members using the REST API and print it on the conversation.

// 1. inject the JWT from the connector to the client on every call
addTokenToClient(connector, connectorApiClient).then((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);
// 3. GET /v3/conversations/{conversationId}/members
client.Conversations.Conversations_GetConversationMembers({ conversationId: conversationId })
.then((res) => printMembersInChannel(message.address, res.obj))
.catch((error) => console.log('Error retrieving conversation members: ' + error.statusText));
});
}
var conversationId = message.address.conversation.id;

// when a group conversation message is recieved,
// get the conversation members using the REST API and print it on the conversation.

// 1. inject the JWT from the connector to the client on every call
addTokenToClient(connector, connectorApiClient).then((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);
// 3. GET /v3/conversations/{conversationId}/members
client.Conversations.Conversations_GetConversationMembers({ conversationId: conversationId })
.then((res) => printMembersInChannel(message.address, res.obj))
.catch((error) => console.log('Error retrieving conversation members: ' + error.statusText));
});
});

// Helper methods
Expand All @@ -96,6 +91,8 @@ function addTokenToClient(connector, clientPromise) {

// Create a message with the member list and send it to the conversationAddress
function printMembersInChannel(conversationAddress, members) {
if(!members || members.length == 0) return;

var memberList = members.map((m) => '* ' + m.name + ' (Id: ' + m.id + ')')
.join('\n ');

Expand Down
2 changes: 1 addition & 1 deletion Node/demo-ContosoFlowers/bot/dialogs/shop.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ library.dialog('/', [
// Ask for delivery address using 'address' library
session.beginDialog('address:/',
{
promptMessage: util.format('%s, please enter the delivery address for these flowers. Include apartment # if needed.', session.message.user.name)
promptMessage: util.format('%s, please enter the delivery address for these flowers. Include apartment # if needed.', session.message.user.name || "User")
});
},
function (session, args) {
Expand Down
8 changes: 0 additions & 8 deletions Node/demo-ContosoFlowers/bot/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ var algo = 'aes-256-ctr';
var password = 'itsasecret!';

function serializeAddress(address) {
var addressCore = {
channelId: address.channelId,
serviceUrl: address.serviceUrl,
user: address.user,
bot: address.bot,
useAuth: true
};

return JSON.stringify(address);
}

Expand Down
File renamed without changes.
9 changes: 2 additions & 7 deletions Node/demo-Search/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ These samples illustrate how to approach dialogs that need to help the user navi

Content is modeled as a catalog of items where each item has several attributes that may be used for navigation, keyword search or display.

| Real Estate Sample | Job Listing Sample|
|--------------------|-------------------|
|[![Deploy to Azure][Deploy Button]][Deploy Node/Search/RealEstateBot]|[![Deploy to Azure][Deploy Button]][Deploy Node/Search/JobListingBot]|


[![Deploy to Azure][Deploy Button]][Deploy Search/Node]
[Deploy Button]: https://azuredeploy.net/deploybutton.png
[Deploy Node/Search/RealEstateBot]: https://azuredeploy.net/?repository=https://github.com/microsoft/BotBuilder-Samples/tree/master/Node/demo-Search/RealEstateBot
[Deploy Node/Search/JobListingBot]: https://azuredeploy.net/?repository=https://github.com/microsoft/BotBuilder-Samples/tree/master/Node/demo-Search/JobListingBot
[Deploy Search/Node]: https://azuredeploy.net

### Prerequisites

Expand Down
27 changes: 0 additions & 27 deletions Node/demo-Search/RealEstateBot/.vscode/launch.json

This file was deleted.

Loading

0 comments on commit 24e9d5a

Please sign in to comment.