Skip to content

Commit 6beb7cb

Browse files
authored
Merge pull request #11 from tompaana/development
Version 1.0.2
2 parents 74f2312 + 74fee79 commit 6beb7cb

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

BotMessageRouting/MessageRouting/MessageRouterManager.cs

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public virtual async Task<MessageRouterResult> HandleActivityAsync(
8686
/// </summary>
8787
/// <param name="partyToMessage">The party to send the message to.</param>
8888
/// <param name="messageActivity">The message activity to send (message content).</param>
89-
/// <returns>The ResourceResponse instance or null in case of an error.</returns>
89+
/// <returns>A valid ResourceResponse instance, if successful. Null in case of an error.</returns>
9090
public async Task<ResourceResponse> SendMessageToPartyByBotAsync(
9191
Party partyToMessage, IMessageActivity messageActivity)
9292
{
@@ -104,13 +104,13 @@ public async Task<ResourceResponse> SendMessageToPartyByBotAsync(
104104
if (botParty != null)
105105
{
106106
messageActivity.From = botParty.ChannelAccount;
107+
messageActivity.Recipient = partyToMessage.ChannelAccount;
107108

108109
MessagingUtils.ConnectorClientAndMessageBundle bundle =
109110
MessagingUtils.CreateConnectorClientAndMessageActivity(
110111
partyToMessage.ServiceUrl, messageActivity);
111112

112-
return await bundle.connectorClient.Conversations.SendToConversationAsync(
113-
(Activity)bundle.messageActivity);
113+
return await SendAsync(bundle);
114114
}
115115

116116
return null;
@@ -122,7 +122,7 @@ public async Task<ResourceResponse> SendMessageToPartyByBotAsync(
122122
/// </summary>
123123
/// <param name="partyToMessage">The party to send the message to.</param>
124124
/// <param name="messageText">The message content.</param>
125-
/// <returns>The ResourceResponse instance or null in case of an error.</returns>
125+
/// <returns>A valid ResourceResponse instance, if successful. Null in case of an error.</returns>
126126
public async Task<ResourceResponse> SendMessageToPartyByBotAsync(Party partyToMessage, string messageText)
127127
{
128128
Party botParty = null;
@@ -139,39 +139,12 @@ public async Task<ResourceResponse> SendMessageToPartyByBotAsync(Party partyToMe
139139
MessagingUtils.CreateConnectorClientAndMessageActivity(
140140
partyToMessage, messageText, botParty?.ChannelAccount);
141141

142-
return await bundle.connectorClient.Conversations.SendToConversationAsync(
143-
(Activity)bundle.messageActivity);
142+
return await SendAsync(bundle);
144143
}
145144

146145
return null;
147146
}
148147

149-
/// <summary>
150-
/// Sends the given message activity to all the aggregation channels, if any exist.
151-
/// </summary>
152-
/// <param name="messageActivity">The message activity to broadcast.</param>
153-
/// <returns></returns>
154-
public async Task BroadcastMessageToAggregationChannelsAsync(IMessageActivity messageActivity)
155-
{
156-
foreach (Party aggregationChannel in RoutingDataManager.GetAggregationParties())
157-
{
158-
await SendMessageToPartyByBotAsync(aggregationChannel, messageActivity);
159-
}
160-
}
161-
162-
/// <summary>
163-
/// Sends the given message to all the aggregation channels, if any exist.
164-
/// </summary>
165-
/// <param name="messageText">The message to broadcast.</param>
166-
/// <returns></returns>
167-
public async Task BroadcastMessageToAggregationChannelsAsync(string messageText)
168-
{
169-
foreach (Party aggregationChannel in RoutingDataManager.GetAggregationParties())
170-
{
171-
await SendMessageToPartyByBotAsync(aggregationChannel, messageText);
172-
}
173-
}
174-
175148
/// <summary>
176149
/// Checks the given parties and adds them to the collection, if not already there.
177150
///
@@ -480,6 +453,34 @@ public virtual async Task<MessageRouterResult> RouteMessageIfSenderIsConnectedAs
480453
return result;
481454
}
482455

456+
/// <summary>
457+
/// Sends a message activity to the conversation using the given bundle.
458+
/// </summary>
459+
/// <param name="bundle">The bundle containing the connector client and the message activity to send.</param>
460+
/// <returns>A valid ResourceResponse instance, if successful. Null in case of an error.</returns>
461+
protected virtual async Task<ResourceResponse> SendAsync(
462+
MessagingUtils.ConnectorClientAndMessageBundle bundle)
463+
{
464+
ResourceResponse resourceResponse = null;
465+
466+
try
467+
{
468+
resourceResponse =
469+
await bundle.connectorClient.Conversations.SendToConversationAsync(
470+
(Activity)bundle.messageActivity);
471+
}
472+
catch (UnauthorizedAccessException e)
473+
{
474+
System.Diagnostics.Debug.WriteLine($"Failed to send message: {e.Message}");
475+
}
476+
catch (Exception e)
477+
{
478+
System.Diagnostics.Debug.WriteLine($"Failed to send message: {e.Message}");
479+
}
480+
481+
return resourceResponse;
482+
}
483+
483484
/// <summary>
484485
/// Ends the conversation(s) of the given party.
485486
/// </summary>

BotMessageRouting/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.0.0")]
36-
[assembly: AssemblyFileVersion("1.0.0.0")]
35+
[assembly: AssemblyVersion("1.0.2.0")]
36+
[assembly: AssemblyFileVersion("1.0.2.0")]

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ conversation.
7272
will indicate whether the message routing logic consumed the activity or not. If the activity was
7373
ignored by the message routing logic, you can e.g. forward it to your dialog.
7474
* `SendMessageToPartyByBotAsync`: Utility method to make the bot send a given message to a given user.
75-
* `BroadcastMessageToAggregationChannelsAsync`: Sends the given message to all the aggregation channels.
7675
* `MakeSurePartiesAreTracked`: A convenient method for adding parties. The given parties are added,
7776
if they are new. This method is called by `HandleActivityAsync` so you don't need to bother
7877
calling this explicitly yourself unless your bot code is a bit more complex.

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 1.0.0.{build}
1+
version: 1.0.2.{build}
22
assembly_info:
33
patch: true
44
file: '**\AssemblyInfo.*'

0 commit comments

Comments
 (0)