I am working on creating a MSTeams BOT. I am using Microsoft.Bot.Builder(4.15.2), Microsoft.Bot.Connector (4.15.2) to send a message to the 1000 bot users asynchronously using the below code.
public async Task SendMessage(string tenantId, ConnectorClient connectorClient, UserDetails user, Activity personalMessageActivity)
{
ChannelAccount member = GetChannelAccount(user.id, user.name);
ConversationParameters conversationParameters = GetConversationParameters(tenantId, member);
string conversationId = user.conversationId;
var resp = await connectorClient.Conversations.SendToConversationAsync(user.conversationId, personalMessageActivity);
}
public async Task SendMessageToUsers(ProactiveMessage proactiveMessage, string tenantId, ConnectorClient connectorClient, UserDetails member, Activity personalMessageActivity)
{
var result = await SendMessage(tenantId, connectorClient, member, personalMessageActivity);
}
Below is the for loop to send message to 1000 users
List<Task> TaskList = new List<Task>();
foreach (UserDetails member in allMembersArr)
{
TaskList.Add(SendMessageToUsers (proactiveMessage, tenantId, connectorClient, member, personalMessageActivity));
}
await Task.WhenAll(TaskList);
It sent a message to few users (approx 600 users) successfully but for the remaining users, I am getting an error “A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.”.
I tried to use multithreading and asynchronous programming but it still fails after sending a messages to approx 600 users.
Below is the error log : enter image description here
Update We tried sending the message from Node Js but we are still not able to send 1000 messages from our bot. We get timeout error from the library for random user on every run. Here is the main code that we are using to send the messages:
const sendMessage = (membersArry, activity) => {
membersArry.forEach((member) => {
connectorClient.conversations.sendToConversation(
member.conversationId,
activity
);
});
}
Library Used:
"botbuilder": "^4.15.0",
"botframework-connector": "^4.15.0",
It sent a message to a few users successfully but for the remaining users, I am getting an error "Error: connect ETIMEDOUT 52.xx.xxx.x:443"
Note:- We are using the Azure Bot with pricing tier - Standard S1