title: 'Operation returned an invalid status code 'badrequest' is returned when the bot is published on Teams channel.: Bot Framework
body: <p>I am a beginner learning the Bot framework in Azure.NET, I came across this bot sample (<a href="https://github.com/tompaana/intermediator-bot-sample" rel="nofollow noreferrer">https://github.com/tompaana/intermediator-bot-sample</a>) which perfectly demonstrates the human-hand off scenario. I could execute it on local host and it worked as expected.</p>
  
  <p>When I published this POC on MS Teams channel through Azure Bot service, The code returns me the exception 'Operation returned an invalid status code 'badrequest'. This occurs particularly when '@Bot GetRequests' is typed in Teams. (This command is used to retrieve the pending accepted requests during human-hand off scenarios.)</p>
  
  <p>Here is the code snippet which is causing the issue:</p>
  
  <pre><code>  //This is the Entry point method of the Bot application
    protected override async Task OnMessageActivityAsync(ITurnContext&lt;IMessageActivity&gt; turnContext, CancellationToken cancellationToken)
    {
  
      if (turnContext.Activity.Text == "@Bot GetRequests")
      {
       await HandleCommandAsync(turnContext);
      }
  
   }
  
   public async virtual Task&lt;bool&gt; HandleCommandAsync(ITurnContext context)
   {
          Activity activity = context.Activity;           
          Command command = Command.FromMessageActivity(activity);          
          bool wasHandled = false;
          Activity replyActivity = null;
          ConversationReference sender = MessageRouter.CreateSenderConversationReference(activity);
  
          switch (command.BaseCommand)
          {               
              case Commands.GetRequests:
  
                  IList&lt;ConnectionRequest&gt; connectionRequests = _messageRouter.RoutingDataManager.GetConnectionRequests();
  
                  replyActivity = activity.CreateReply();
  
                  replyActivity.Attachments = CreateMultipleConnectionRequestCards(_messageRouter,
                         connectionRequests, activity.Recipient?.Name);
  
                  replyActivity.ChannelData = JsonConvert.SerializeObject(connectionRequests);                                
                  wasHandled = true;                  
                  break;                             
         }
  
         if (replyActivity != null)
         {
              //Exception is thrown here when the Bot is published to Teams channel'
              await context.SendActivityAsync(replyActivity);
         }            
          return wasHandled;
     }
  
  
     public static IList&lt;Attachment&gt; CreateMultipleConnectionRequestCards(MessageRouter messageRouter,
          IList&lt;ConnectionRequest&gt; connectionRequests, string botName = null)
      {
          IList&lt;Attachment&gt; attachments = new List&lt;Attachment&gt;();
  
          foreach (ConnectionRequest connectionRequest in connectionRequests)
          {
              attachments.Add(CreateConnectionRequestCard(messageRouter, connectionRequest, botName).ToAttachment());
          }
          return attachments;
    }
  </code></pre>
  
  <p>I am just curious to know that if anyone in the developer community has ever been through the similar problem. If yes, I would really appreciate if I can get any help on this to come out of the issue.</p>