@@ -86,7 +86,7 @@ public virtual async Task<MessageRouterResult> HandleActivityAsync(
86
86
/// </summary>
87
87
/// <param name="partyToMessage">The party to send the message to.</param>
88
88
/// <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>
90
90
public async Task < ResourceResponse > SendMessageToPartyByBotAsync (
91
91
Party partyToMessage , IMessageActivity messageActivity )
92
92
{
@@ -104,13 +104,13 @@ public async Task<ResourceResponse> SendMessageToPartyByBotAsync(
104
104
if ( botParty != null )
105
105
{
106
106
messageActivity . From = botParty . ChannelAccount ;
107
+ messageActivity . Recipient = partyToMessage . ChannelAccount ;
107
108
108
109
MessagingUtils . ConnectorClientAndMessageBundle bundle =
109
110
MessagingUtils . CreateConnectorClientAndMessageActivity (
110
111
partyToMessage . ServiceUrl , messageActivity ) ;
111
112
112
- return await bundle . connectorClient . Conversations . SendToConversationAsync (
113
- ( Activity ) bundle . messageActivity ) ;
113
+ return await SendAsync ( bundle ) ;
114
114
}
115
115
116
116
return null ;
@@ -122,7 +122,7 @@ public async Task<ResourceResponse> SendMessageToPartyByBotAsync(
122
122
/// </summary>
123
123
/// <param name="partyToMessage">The party to send the message to.</param>
124
124
/// <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>
126
126
public async Task < ResourceResponse > SendMessageToPartyByBotAsync ( Party partyToMessage , string messageText )
127
127
{
128
128
Party botParty = null ;
@@ -139,39 +139,12 @@ public async Task<ResourceResponse> SendMessageToPartyByBotAsync(Party partyToMe
139
139
MessagingUtils . CreateConnectorClientAndMessageActivity (
140
140
partyToMessage , messageText , botParty ? . ChannelAccount ) ;
141
141
142
- return await bundle . connectorClient . Conversations . SendToConversationAsync (
143
- ( Activity ) bundle . messageActivity ) ;
142
+ return await SendAsync ( bundle ) ;
144
143
}
145
144
146
145
return null ;
147
146
}
148
147
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
-
175
148
/// <summary>
176
149
/// Checks the given parties and adds them to the collection, if not already there.
177
150
///
@@ -480,6 +453,34 @@ public virtual async Task<MessageRouterResult> RouteMessageIfSenderIsConnectedAs
480
453
return result ;
481
454
}
482
455
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
+
483
484
/// <summary>
484
485
/// Ends the conversation(s) of the given party.
485
486
/// </summary>
0 commit comments