0

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

  • Could you please share the error log, so that we can investigate from our end? – Sayali-MSFT Nov 22 '22 at 09:51
  • @Sayali-MSFT, the error log is updated. – Sandesh Sawant Nov 25 '22 at 06:04
  • We are not able to repro the issue. It's working fine. we are sending the message to 1080 users. It is successfully sent to all. Microsoft Teams Version 1.5.00.32474 (64-bit). [![enter image description here][1]][1][1]: https://i.stack.imgur.com/OpDAQ.png – Sayali-MSFT Nov 25 '22 at 13:35
  • @Sayali-MSFT, 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: members.foreach(async (member, index) => { let activity = MessageFactory.text("This is my Message"); return connectorClient.conversations.sendToConversation( member.conversationId, activity ); }); Library Used: "botbuilder": "^4.15.0", "botframework-connector": "^4.15.0", Note: - We are using the Azure Bot with pricing tier - Standard S1 – Devesh Tiwari Dec 15 '22 at 10:41
  • @Sayali-MSFT Previously we tried with bot framework in C# and now we are trying with Node JS. We have updated the question with what code we are using to send. Let me know if there is anything wrong, we are doing – Devesh Tiwari Dec 15 '22 at 10:47
  • Could you please try with the below sample code-https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/main/samples/bot-conversation/nodejs/bots/teamsConversationBot.js#L221 – Sayali-MSFT Dec 26 '22 at 09:06
  • @Sayali-MSFT Actually, we are not using the 'Context' object to send the messages. We have a tab in MS Teams from where we are sending the messages. We are using the 'connector Client' from the 'botframework-connector' to send the messages hence the code sample that you suggested won't work in our case. I have mentioned the code sample in the question that we are using to send the messages. FYI, our bot is hosted on Azure with the 'S1 Standard' plan. I don't know if it's playing any role in it because I think ultimatly, the messages goes via the bot so i thought it good to let you know. – Devesh Tiwari Jan 12 '23 at 11:52

0 Answers0