Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update bot templates to stop sending a message on error, when the activity is not a message directed to it #10865

Open
aosolis opened this issue Feb 14, 2024 · 5 comments
Assignees

Comments

@aosolis
Copy link

aosolis commented Feb 14, 2024

Describe the bug
We have a problem in Teams with bots replying to an invoke or conversationUpdate activity unexpectedly, which shows up as spam messages to the General channel. One source of this spam are bots that indiscriminately reply with an error message in their error handler.

Could we update the TTK templates to handle this error condition correctly? Patterns like

// Send a message to the user

are problematic when the error happens in the context of an activity that's not a message directed at the bot.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

VS Code Extension Information (please complete the following information):

  • OS: [e.g. iOS]
  • Version [e.g. 22]

CLI Information (please complete the following information):

  • OS: [e.g. iOS8.1]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Copy link
Contributor

Thank you for contacting us! Any issue or feedback from you is quite important to us. We will do our best to fully respond to your issue as soon as possible. Sometimes additional investigations may be needed, we will usually get back to you within 2 days by adding comments to this issue. Please stay tuned.

@aosolis aosolis changed the title Update bot templates to *not* reply to an error when the activity is not a message directed to it Update bot templates to stop sending a message on error, when the activity is not a message directed to it Feb 14, 2024
@therealjohn
Copy link
Contributor

therealjohn commented Feb 15, 2024

@aosolis and I chatted about this and a message type check works well. The code can be improved like this:

const onTurnErrorHandler = async (context, error) => {  
     console.error(`\n [onTurnError] unhandled error: ${error}`);

    // Only send error message for user messages, not for other message types so the bot doesn't spam a channel or chat.
    if(context.activity.type === 'message') {
        // Send a trace activity, which will be displayed in Bot Framework Emulator
        await context.sendTraceActivity(
          "OnTurnError Trace",
          `${error}`,
          "https://www.botframework.com/schemas/error",
          "TurnError"
        );

        // Send a message to the user
        await context.sendActivity("The bot encountered an error or bug.");
    }
};

With this change an error message outputs as a message only when a user is messaging the bot. Other activity types like conversationUpdate, invoke, etc. won't result in an error in the chat.

@adashen adashen added the needs more info Need user to provide more info label Feb 19, 2024
Copy link
Contributor

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

@microsoft-github-policy-service microsoft-github-policy-service bot added the no recent activity The issue labeled needs more info gets no reply from issue owner in time label Feb 27, 2024
Copy link
Contributor

Due to lack of details for further investigation, we will archive the issue for now. In case you still have following-up questions on this issue, please always feel free to reopen the issue by clicking ‘reopen issue’ button below the comment box. We will get back to you as soon as possible.

@qinezh qinezh reopened this Mar 1, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed the no recent activity The issue labeled needs more info gets no reply from issue owner in time label Mar 1, 2024
@qinezh qinezh removed the needs more info Need user to provide more info label Mar 4, 2024
@qinezh qinezh self-assigned this Mar 4, 2024
@qinezh
Copy link
Contributor

qinezh commented Mar 20, 2024

@aosolis the bot template is updated in latest Teams Toolkit (v5.6.0), please feel free to have a try😄 (For C#, the bot template changes will be released along with VS 17.10 Preview 3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants