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

[.NET SDK] Telegram client doesn't recognize replies from bot as replies

Open akakoychenko opened this issue 8 years ago • 13 comments

Bot Info

  • SDK Platform: .NET
  • SDK Version: 3.14.1.1
  • Active Channels: Telegram
  • Deployment Environment: own server + Azure Bot Service,

Issue Description

Telegram client (Telegram X for Android) still shows the waiting picture on the bot's button after the bot reply. After a while Telegram also shows a notification. "The bot doesn't respond. Try again later ". Nevertheless, the reply from the bot shows correct.

Code Example

var message = messageFromUser.CreateReply() ... filling the message var result = await _connector.Conversations.ReplyToActivityAsync(message);

Reproduction Steps

  1. get the message with buttons from bot
  2. push any button
  3. wait for the bot reply

Expected Behavior

The waiting pictogram (small rolling circle) on the button disappears

Actual Results

The waiting pictogram still active. After 30 seconds-1 minute. Telegram shows notification "The bot doesn't respond. Try again later "

akakoychenko avatar Mar 30 '18 09:03 akakoychenko

What version of Android are you using? Is Telegram updated to the latest executable?

nodeomega avatar Apr 03 '18 22:04 nodeomega

Android 7.0, Telegram X 0.20.6.909-arm64-v8a (latest version, published on April,  1)

akakoychenko avatar Apr 03 '18 23:04 akakoychenko

Apologies for the wait are you still experiencing this problem? It seems like maybe ReplyToActivityAsync could be your problem with this use case.

Here is a code snippet that creates a message and adds buttons. When used with the telegram channel and when one of the buttons is pressed, there is no timeout and the value of the button is returned and processed by the bot, which echoes the value back to the chat.

       private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
        {
            var activity = await result as Activity;


            // Calculate something for us to return
            int length = (activity.Text ?? string.Empty).Length;
            var message = activity.CreateReply();
            message.Text = $"You sent {activity.Text} which was {length} characters";
            
            message.SuggestedActions = new SuggestedActions()
            {
                Actions = new List<CardAction>()
                {
                    new CardAction(){ Title = "Blue", Type=ActionTypes.ImBack, Value="Blue" },
                    new CardAction(){ Title = "Red", Type=ActionTypes.ImBack, Value="Red" },
                    new CardAction(){ Title = "Green", Type=ActionTypes.ImBack, Value="Green" }
                }
            };
            await context.PostAsync(message);

            context.Wait(MessageReceivedAsync);
        }

Please let me know if this pattern works for you.

sbuffkin avatar Jun 27 '18 20:06 sbuffkin

I don't work with IDialogContext, using Activity instead Here is a sample of my code

    public class MessagesController : ApiController
    {
        public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
        {
            ...
        }
    }

akakoychenko avatar Jun 28 '18 10:06 akakoychenko

And regarding the problem - yes, I still experiencing the problem

akakoychenko avatar Jun 28 '18 13:06 akakoychenko

Can you please provide a complete minimum reproducible example with actual code? You are leaving out the actual code you are using in all of your code examples.

JasonSowers avatar Jun 28 '18 15:06 JasonSowers

    [BotAuthentication]
    public class MessagesController : ApiController
    {
        public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
        {
            Activity reply = activity.CreateReply();
            reply.AttachmentLayout = AttachmentLayoutTypes.List;
            reply.Attachments = new List<Attachment>()
            {
                new HeroCard
                {
                    Buttons = new [] 
                    {
                        new CardAction
                        {
                            Type = "imBack",
                            Title = "Push me!",
                            Value = "value"
                        }
                    }.ToList()
                }
                .ToAttachment()
            };

            using (var client = new ConnectorClient(
                new Uri(activity.ServiceUrl),
                new MicrosoftAppCredentials(
                    ConfigurationManager.AppSettings["MicrosoftAppId"],
                    ConfigurationManager.AppSettings["MicrosoftAppPassword"])
                ))
            {
                await client.Conversations.ReplyToActivityAsync(reply);
            }
            return new HttpResponseMessage(HttpStatusCode.OK);
        }
    }

akakoychenko avatar Jun 28 '18 15:06 akakoychenko

Just to double check, are you seeing this implementation work in any other channel? Is it only broken in Telegram?

sbuffkin avatar Jun 28 '18 21:06 sbuffkin

I use telegram and skype only. Skype does not provide waiting wheel at all, so this problem is not relevant for Skype, and this code works with Skype perfectly.  null

akakoychenko avatar Jun 29 '18 20:06 akakoychenko

Have you tried debugging this locally? https://blog.botframework.com/2017/10/19/debug-channel-locally-using-ngrok/

EricDahlvang avatar Jun 29 '18 21:06 EricDahlvang

Yes, I don't use ngrok, but I have forwarded traffic via IIS url rewrite to the bot, running from VS. Nevertheless, it works the same from both IIS and VS. null

akakoychenko avatar Jun 29 '18 21:06 akakoychenko

Currently herocard will not output its button values to the chatlog in telegram when they are pressed. However SuggestedActions will do this. I've edited my previous example to fit your code to illustrate what this looks like. Unfortunately there is not any way to have that happen with herocard.

That said the value from your button in herocard will be sent back to the bot, so it will still act as though it was sent that reply, the user reply/button press just won't appear in the chatlog. For the purposes of telegram a herocard "ImBack" action will look the same as a "PostBack"

public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
        {
            Activity reply = activity.CreateReply();
            reply.Text = "choose an action";
            reply.SuggestedActions = new SuggestedActions()
            {
                Actions = new List<CardAction>()
                        {   new CardAction()
                            {
                                Type = "imBack",
                                Title = "Push me!",
                                Value = "value"
                            }
                        }
            };


            using (var client = new ConnectorClient(
                new Uri(activity.ServiceUrl),
                new MicrosoftAppCredentials(
                    ConfigurationManager.AppSettings["MicrosoftAppId"],
                    ConfigurationManager.AppSettings["MicrosoftAppPassword"])
                ))
            {
                await client.Conversations.ReplyToActivityAsync(reply);
            }
            return new HttpResponseMessage(HttpStatusCode.OK);
        }

sbuffkin avatar Jul 02 '18 20:07 sbuffkin

Closing, please reopen if you need further help.

sbuffkin avatar Jul 17 '18 15:07 sbuffkin