[.NET SDK] Telegram client doesn't recognize replies from bot as replies
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
- get the message with buttons from bot
- push any button
- 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 "
What version of Android are you using? Is Telegram updated to the latest executable?
Android 7.0, Telegram X 0.20.6.909-arm64-v8a (latest version, published on April, 1)
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.
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)
{
...
}
}
And regarding the problem - yes, I still experiencing the problem
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.
[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);
}
}
Just to double check, are you seeing this implementation work in any other channel? Is it only broken in Telegram?
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
Have you tried debugging this locally? https://blog.botframework.com/2017/10/19/debug-channel-locally-using-ngrok/
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
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);
}
Closing, please reopen if you need further help.