Forum Discussion
Teams sending multiple responses to interactive bot
Maury33308 - Could you please refer this if it helps?
Rate limiting for bots - Teams | Microsoft Learn
Thank you for your response Prasad_Das-MSFT.
The problem is happening when I am sending the message, but when the user clicks a button in Teams to send me their response.
- Prasad_Das-MSFTSep 21, 2023
Microsoft
Maury33308 - To prevent multiple messages from being sent in quick succession, you can implement throttling in your code. Throttling limits the rate at which messages can be sent, ensuring that only one message is sent at a time. Rate limiting for bots - Teams | Microsoft Learn
Also, you can check for event duplication: It's possible that the button click event is being triggered multiple times due to event duplication. This can happen if there are multiple event handlers registered for the same event. Make sure that you have only one event handler registered for the button click event to avoid duplicate messages.Here is an example of how to send a message in response to a button click event using the Teams JavaScript SDK:
// Handle button click event async function handleButtonClick(event) { // Get the conversation ID and user ID const conversationId = event.conversation.id; const userId = event.user.id; try { // Create the conversation const conversation = await teamsClient.conversations.createConversation({ bot: { id: '<your-bot-id>' }, members: [{ id: userId }], }); // Get the conversation ID const newConversationId = conversation.id; // Send the message await teamsClient.conversations.sendToConversation(newConversationId, { type: 'message', text: 'This is a response to the button click event.', }); } catch (error) { console.error('Error sending message:', error); } }Thanks,
Prasad Das
------------------------------------------------------------------------------------------
If the response is helpful, please click "**Mark as Best Response**" and like it. You can share your feedback via Microsoft Teams Developer Feedback link.