botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Telegram channel issue: [400] Bad Request (BUTTON_DATA_INVALID)

Open 0xeminneo opened this issue 8 years ago • 17 comments

Bot Info

  • SDK Platform: Node.js
  • SDK Version: 3.14.0
  • Active Channels: Telegram
  • Deployment Environment: Azure App Service (Azure Web App)

Issue Description

Telegram channel fails with following error in console:

Error: POST to 'https://telegram.botframework.com/v3/conversations/370544732/activities/K1CfSzs9lFJ' failed: [400] Bad Request
    at Request._callback (D:\home\site\wwwroot\node_modules\botbuilder\lib\bots\ChatConnector.js:559:46)
    at Request.self.callback (D:\home\site\wwwroot\node_modules\request\request.js:186:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:191:7)
    at Request.<anonymous> (D:\home\site\wwwroot\node_modules\request\request.js:1163:10)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:188:7)
    at IncomingMessage.<anonymous> (D:\home\site\wwwroot\node_modules\request\request.js:1085:12)
    at IncomingMessage.g (events.js:291:16)
    at emitNone (events.js:91:20)

In channel status log I see the following error messages:

{"ok":false,"error_code":400,"description":"Bad Request: BUTTON_DATA_INVALID"}

Code Example

var restify = require('restify');
var builder = require('botbuilder');

// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
   console.log('%s listening to %s', server.name, server.url); 
});

// Create chat connector for communicating with the Bot Framework Service
var connector = new builder.ChatConnector({
    appId: process.env.MicrosoftAppId,
    appPassword: process.env.MicrosoftAppPassword
});

// Listen for messages from users 
server.post('/api/messages', connector.listen());

var bot = new builder.UniversalBot(connector, [
    function (session) {
        session.send("Hello!");
        builder.Prompts.choice(session, "Please select your choice, clicking the button",
                                ["Button 1", "Button 2"], { listStyle: 3 });
    },
    function(session, results) {
        if (results.response.index == 0) {
            session.beginDialog('customDialog');
        } else {
            session.endDialog();          
        }
    }
]);

bot.on('conversationUpdate', function (message) {
    if (message.membersAdded) {
        message.membersAdded.forEach(function (identity) {
            if (identity.id === message.address.bot.id) {
                bot.beginDialog(message.address, '/');
            }
        });
    }
});

Reproduction Steps

  1. Create bot application in Azure App Service
  2. Edit app.js and add the code example above
  3. Create a Telegram bot
  4. Add and register Telegram channel
  5. Try to start conversation with /start command

Expected Behavior

Expected Telegram channel to work properly.

Actual Results

When I start a conversation using /start command in Telegram, bot does not respond anything.

0xeminneo avatar Feb 22 '18 15:02 0xeminneo

Hi,

Any thoughts/updates on this issue? Telegram channel still does not work.

0xeminneo avatar Feb 26 '18 12:02 0xeminneo

I am unable to replicate this issue, as this appears to be working normally for me. However, I did create a dialog named "customDialog" when I was attempting to replicate this, as I was getting a message saying that dialog wasn't found when I first attempted to run your sample.

Was the code sample the entirety of the code, or did you have other dialogs set up?

nodeomega avatar Feb 26 '18 19:02 nodeomega

I managed to resolve the issue, by recreating Bot Channels Registration object, but eventually I did not get the reason of problem. It is a bit strange since initially everything worked fine.

0xeminneo avatar Feb 27 '18 13:02 0xeminneo

Has the issue recurred since recreating the Bot Channels Registration object?

nodeomega avatar Feb 27 '18 17:02 nodeomega

Now I am getting this issue only if try to render in Telegram Prompts.choice with large number of buttons (e.g. 30). It seems there is a restriction on it, because of Direct Channel and Web Chat works fine.

0xeminneo avatar Mar 02 '18 09:03 0xeminneo

I do not appear to be replicating the issue with large numbers of buttons in Telegram, as I am not getting an error when I tested in Telegram with 30 buttons. Did you exceed 30 by any chance?

nodeomega avatar Mar 12 '18 23:03 nodeomega

I have the same issue with telegram channel working from C#. In web Chat/skype channels code work fine. Bot showing first Greeting message and than failing on sending first question

Packages: "Microsoft.Bot.Builder" version="3.14.0.7" targetFramework="net46" "Microsoft.Bot.Builder.Azure" version="3.2.5" targetFramework="net46" "Microsoft.Bot.Builder.History" version="3.14.0.7" targetFramework="net46" "Microsoft.Bot.Connector" version="3.14.0.7" targetFramework="net46" What I see on Azure portal: 3/21/2018, 3:18:07 PM | {"ok":false,"error_code":400,"description":"Bad Request: BUTTON_DATA_INVALID"}

my code: private async Task MessageReceivedAsync(IDialogContext context, IAwaitable result) { //work fine await WelcomeMessage(context); //exception here await Question1Async(context); } //ignore text on Russian language- it's not an issue. #region Здравствуйте, Иван Иванович, меня зовут Протос. Я бот call-центра . private const string GreetingMessage = @"Здравствуйте, Иван Иванович"; private async Task WelcomeMessage(IDialogContext context) { var reply = context.MakeMessage(); reply.TextFormat = "markdown"; reply.Text = GreetingMessage; await context.PostAsync(reply); } private const string NoMoreWorkingInSberbank = "Да, я более не работаю в системе XXX."; private const string StillWorkingInSberbank = "Это ошибка, я все еще работаю в системе XXX.";

    private async Task Question1Async(IDialogContext context)
    {
        var m = context.MakeMessage();
        m.AddKeyboardCard("Правильно ли я понимаю, что на данный момент Вы уже не работаете в системе XXX?", new[] { NoMoreWorkingInSberbank, StillWorkingInSberbank });
        await context.PostAsync(m);
        context.Wait(Question1ResponseReceivedAsync);
    }

In telegram windows I can see: "POST to igorsber failed: POST to the bot's endpoint failed with HTTP status 500"

In application Insights error looks like: { "message": "An error has occurred.", "exceptionMessage": "Operation returned an invalid status code 'BadRequest'", "exceptionType": "Microsoft.Bot.Connector.ErrorResponseException", "stackTrace": " at Microsoft.Bot.Connector.Conversations.d__8.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Connector.ConversationsExtensions.d__7.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.AlwaysSendDirect_BotToUser.d__4.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.InputHintQueue.d__4.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.AutoInputHint_BotToUser.d__3.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.MapToChannelData_BotToUser.d__3.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.LogBotToUser.d__4.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.DialogContext.d__12.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.SbInterviewBot.Dialogs.RootDialog.d__7.MoveNext() in C:\Users\igorsych\Desktop\Sber\Bots\src\Dialogs\RootDialog.cs:line 45\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.SbInterviewBot.Dialogs.RootDialog.d__2.MoveNext() in C:\Users\igorsych\Desktop\Sber\Bots\src\Dialogs\RootDialog.cs:line 23\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume1.<Rest>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Internals.Fibers.Wait2.<Microsoft-Bot-Builder-Internals-Fibers-IWait-PollAsync>d__19.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Internals.Fibers.Frame1.<Microsoft-Bot-Builder-Internals-Fibers-IFrameLoop<C>-PollAsync>d__9.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Internals.Fibers.Fiber1.<Microsoft-Bot-Builder-Internals-Fibers-IFiberLoop-PollAsync>d__16.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at Microsoft.Bot.Builder.Internals.Fibers.Wait2.Microsoft.Bot.Builder.Internals.Fibers.IAwaiter<T>.GetResult()\r\n at Microsoft.Bot.Builder.Dialogs.Chain.LoopDialog1.d__3.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume1.<Rest>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Internals.Fibers.Wait2.<Microsoft-Bot-Builder-Internals-Fibers-IWait-PollAsync>d__19.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Internals.Fibers.Frame1.<Microsoft-Bot-Builder-Internals-Fibers-IFrameLoop<C>-PollAsync>d__9.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Internals.Fibers.Fiber1.<Microsoft-Bot-Builder-Internals-Fibers-IFiberLoop-PollAsync>d__16.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.d__23.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Inte

SychevIgor avatar Mar 21 '18 12:03 SychevIgor

@SychevIgor have you tried recreating the Bot Connector Registration object? The original requester said that helped initially.

@easkerov I am still investigating the issue regarding the large number of prompt buttons. Also, did the Invalid Button Data 400 error show up again?

nodeomega avatar Mar 22 '18 18:03 nodeomega

@nodeomega I've just tried to reproduce issue again (with number of options 66) and can confirm the error BUTTON_DATA_INVALID with large number of prompt buttons. I've changed list style to listStyle: builder.ListStyle.auto to render prompt as numbered list or buttons automatically depends on array size. In this case when number of items in choice array is large it always render it as numbered list.

0xeminneo avatar Mar 24 '18 19:03 0xeminneo

@nodeomega yes, I tried. Not helped.

SychevIgor avatar Mar 25 '18 05:03 SychevIgor

@nodeomega I don't know what was happened, but after some days (and redeploy) telegram starts showing everything right. I didn't change the boot code or any dependencies (styles on a default.html was a reason to redeploy)

SychevIgor avatar Mar 31 '18 07:03 SychevIgor

@easkerov I have not been able to repro the BUTTON_DATA_INVALID message you are getting, even when I set it to listStyle: 3. (this sets it to use buttons always) I used 67 choices for the prompt as well with this data:

// Test data: 1980's (mostly) cartoon character names.
var promptButtons = ["Megatron", "Starscream", "Soundwave", "Skywarp", "Thundercracker", "Rumble", "Ravage", "Laserbeak", "Frenzy", "Astrotrain", 
"Devestator", "Menesor", "Bruticus", "Predaking", "Octane", "Galvatron", "Cyclonus", "Scourge", "Scorpinok", "Ramjet", 
"Trypticon", "Sideways", "Barricade", "Shockwave", "Nemesis Prime", "Optimus Prime", "Bumblebee", "Ironhide", "Ratchet", "Blaster", 
"Cliffjumper", "Superion", "Computron", "Grimlock", "Slag", "Swoop", "Hot Rod", "Rodimus Prime", "Metroplex", "Omega Supreme", 
"Unicron", "Primus", "Cobra Commander", "Optimus Primal", "Duke", "Lady Jaye", "He-Man", "She-Ra", "Orko", "Man-At-Arms", 
"Lion-O", "Cheetara", "Tigra", "Panthro", "Snarf", "Jaga", "Mumm-Ra", "Jem", "Skeletor", "Evil-Lyn", 
"Hordak", "Stinkor", "Hulk", "Thor", "Iron Man", "Black Widow", "Loki"];

var bot = new builder.UniversalBot(connector, [
    function (session) {
        session.send("Hello!");
        builder.Prompts.choice(session, "Please select your choice, clicking the button",
                                promptButtons, { listStyle: builder.ListStyle.auto });
    },
// ........ more code follows

Now with builder.ListStyle.auto, yes, I am seeing it does a numbered list instead with the large amount of choices in "Test in Web Chat", but it rendered as buttons in my Telegram client. (Windows 10, Telegram Desktop 1.2.17) - Is this the version of Telegram you are using? If not, what Telegram version and platform are you running?

@SychevIgor There has been an updated deployment of our Telegram channel within the last week or two, perhaps that might have accounted for the showing everything right now. Is everything alright now or are we still seeing an issue?

nodeomega avatar Apr 10 '18 22:04 nodeomega

@easkerov on my side- everything works fine.

SychevIgor avatar Apr 11 '18 03:04 SychevIgor

@nodeomega I am using Telegram 3.8.2.119501 on macOS (High Sierra) and Telegram X on Android. I will try to check on Windows desktop client.

0xeminneo avatar Apr 15 '18 18:04 0xeminneo

@easkerov Telegram on MacOS does have a couple issues that we are aware of, and that I have made the Telegram team aware of as well (such as repeating prompt choices). I'm still awaiting feedback from the Telegram team on the issue request I have opened with them a few weeks ago.

Using another version of Telegram such as Windows desktop is recommended at this time.

nodeomega avatar Apr 16 '18 20:04 nodeomega

I am closing this issue as it has been inactive for an extended period. If this issue persists or recurs, feel free to open a new support request. Thank you.

nodeomega avatar Apr 25 '18 18:04 nodeomega

@nisha1142 This repository you are posting to is for the Microsoft BotBuilder library. Telegram happens to be one of the channels we support in terms of bots using BotBuilder framework on said channel. Mr. Pavel Durov of Telegram does not have any bearing on this repository.

nodeomega avatar Jun 21 '18 22:06 nodeomega