Skip to content

Commit

Permalink
Merge pull request #11 from tompaana/development
Browse files Browse the repository at this point in the history
Version 1.0.2
  • Loading branch information
tompaana authored Jan 25, 2018
2 parents 74f2312 + 74fee79 commit 6beb7cb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
65 changes: 33 additions & 32 deletions BotMessageRouting/MessageRouting/MessageRouterManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public virtual async Task<MessageRouterResult> HandleActivityAsync(
/// </summary>
/// <param name="partyToMessage">The party to send the message to.</param>
/// <param name="messageActivity">The message activity to send (message content).</param>
/// <returns>The ResourceResponse instance or null in case of an error.</returns>
/// <returns>A valid ResourceResponse instance, if successful. Null in case of an error.</returns>
public async Task<ResourceResponse> SendMessageToPartyByBotAsync(
Party partyToMessage, IMessageActivity messageActivity)
{
Expand All @@ -104,13 +104,13 @@ public async Task<ResourceResponse> SendMessageToPartyByBotAsync(
if (botParty != null)
{
messageActivity.From = botParty.ChannelAccount;
messageActivity.Recipient = partyToMessage.ChannelAccount;

MessagingUtils.ConnectorClientAndMessageBundle bundle =
MessagingUtils.CreateConnectorClientAndMessageActivity(
partyToMessage.ServiceUrl, messageActivity);

return await bundle.connectorClient.Conversations.SendToConversationAsync(
(Activity)bundle.messageActivity);
return await SendAsync(bundle);
}

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

return await bundle.connectorClient.Conversations.SendToConversationAsync(
(Activity)bundle.messageActivity);
return await SendAsync(bundle);
}

return null;
}

/// <summary>
/// Sends the given message activity to all the aggregation channels, if any exist.
/// </summary>
/// <param name="messageActivity">The message activity to broadcast.</param>
/// <returns></returns>
public async Task BroadcastMessageToAggregationChannelsAsync(IMessageActivity messageActivity)
{
foreach (Party aggregationChannel in RoutingDataManager.GetAggregationParties())
{
await SendMessageToPartyByBotAsync(aggregationChannel, messageActivity);
}
}

/// <summary>
/// Sends the given message to all the aggregation channels, if any exist.
/// </summary>
/// <param name="messageText">The message to broadcast.</param>
/// <returns></returns>
public async Task BroadcastMessageToAggregationChannelsAsync(string messageText)
{
foreach (Party aggregationChannel in RoutingDataManager.GetAggregationParties())
{
await SendMessageToPartyByBotAsync(aggregationChannel, messageText);
}
}

/// <summary>
/// Checks the given parties and adds them to the collection, if not already there.
///
Expand Down Expand Up @@ -480,6 +453,34 @@ public virtual async Task<MessageRouterResult> RouteMessageIfSenderIsConnectedAs
return result;
}

/// <summary>
/// Sends a message activity to the conversation using the given bundle.
/// </summary>
/// <param name="bundle">The bundle containing the connector client and the message activity to send.</param>
/// <returns>A valid ResourceResponse instance, if successful. Null in case of an error.</returns>
protected virtual async Task<ResourceResponse> SendAsync(
MessagingUtils.ConnectorClientAndMessageBundle bundle)
{
ResourceResponse resourceResponse = null;

try
{
resourceResponse =
await bundle.connectorClient.Conversations.SendToConversationAsync(
(Activity)bundle.messageActivity);
}
catch (UnauthorizedAccessException e)
{
System.Diagnostics.Debug.WriteLine($"Failed to send message: {e.Message}");
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine($"Failed to send message: {e.Message}");
}

return resourceResponse;
}

/// <summary>
/// Ends the conversation(s) of the given party.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions BotMessageRouting/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.2.0")]
[assembly: AssemblyFileVersion("1.0.2.0")]
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ conversation.
will indicate whether the message routing logic consumed the activity or not. If the activity was
ignored by the message routing logic, you can e.g. forward it to your dialog.
* `SendMessageToPartyByBotAsync`: Utility method to make the bot send a given message to a given user.
* `BroadcastMessageToAggregationChannelsAsync`: Sends the given message to all the aggregation channels.
* `MakeSurePartiesAreTracked`: A convenient method for adding parties. The given parties are added,
if they are new. This method is called by `HandleActivityAsync` so you don't need to bother
calling this explicitly yourself unless your bot code is a bit more complex.
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1.0.0.{build}
version: 1.0.2.{build}
assembly_info:
patch: true
file: '**\AssemblyInfo.*'
Expand Down

0 comments on commit 6beb7cb

Please sign in to comment.