Botframework-sdk: Issue in getting callback query from Telegram

Created on 2 Nov 2016  路  16Comments  路  Source: microsoft/botframework-sdk

Hi,
I sent the following message to Telegram as an inline message into a group conversation.
I got the message in a correct format with a callback button.
BUT the callback button did not work properly. As I clicked on it, I did not get any callback query in
my bot. Any suggestion? @eanders-MS

{
  "method": "answerInlineQuery",
  "parameters": {
    "inline_query_id": "479778281665093155",
    "results": [
      {
        "type": "photo",
        "id": "43543654675",
        "photo_url": "https://upload.wikimedia.org/wikipedia/en/archive/a/a9/20151112035044!Banyan_Tree_(_Shiv_Bajrang_Dham_Kishunpur).jpeg",
        "thumb_url": "https://upload.wikimedia.org/wikipedia/en/archive/a/a9/20151112035044!Banyan_Tree_(_Shiv_Bajrang_Dham_Kishunpur).jpeg",
        "reply_markup": {
          "inline_keyboard": [
            [
              {
                "text": "Click On Me",
                "callback_data": "Click"
              }
            ]
          ]
        }
      }
    ]
  }
}
help wanted

Most helpful comment

@dimoibiehg I had a look through our service logs, and found what I think is a transaction between your bot and Telegram. The message had an invalid conversation id. It was set to the name of your bot. This is not a field you need to set explicitly. It gets initialized for you when you call activity.CreateReply().

All 16 comments

As I found, it might be not implemented in Bot Framework. Because the result of callback button is a Callback Query which the message is embedded in it; hence, I think this is not implemented in custom messaging with Telegram in Bot Framework. Is this true?

This should work. It looks like you might be sending the incorrect value for the inline_query_id value. Be sure to send the inline_query.id value from the Telegram message, not the Bot Framework activity. The native Telegram message can be found in the channelData/sourceEvent of the incoming activity.

Thanks @eanders-MS . As you said, I've gotten the inline_query.id like the following:

JToken token = JObject.Parse(activity.ChannelData.ToString());
if (token["inline_query"] != null)
{
    string query = (string)token["inline_query"]["query"];
    string queryId = (string)token["inline_query"]["id"];
}

But it didn't worked, as I mentioned in the issue report.

@dimoibiehg I had a look through our service logs, and found what I think is a transaction between your bot and Telegram. The message had an invalid conversation id. It was set to the name of your bot. This is not a field you need to set explicitly. It gets initialized for you when you call activity.CreateReply().

Many Thanks @eanders-MS . As you said, I send my response like the following code:

var reply = activity.CreateReply();
reply.ChannelData = requestJson;
await connector.Conversations.ReplyToActivityAsync(reply);

Is there any guess about where Conversation Id is changed, as I didn't set the conversation Id manually?

Dear @eanders-MS,
Also my entire sample code comes in the following. It is an inline bot.

public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
   ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
   if (activity.ChannelId == "telegram")
   {
      var requestJson = "";
      JToken token = JObject.Parse(activity.ChannelData.ToString());
      if (token["inline_query"] != null)
      {
         string query = (string)token["inline_query"]["query"];
         string queryId = (string)token["inline_query"]["id"];
         requestJson = "{";
         requestJson += "'method': 'answerInlineQuery',";
         requestJson += "'parameters': {";
         requestJson += "'inline_query_id': '" + queryId + "',";
         requestJson += "'results': [";
         requestJson += "{";
         requestJson += "'type': 'photo',";
         requestJson += "'id': '" + (new Guid()).ToString().Substring(0, 6) + "',";
         requestJson += "'photo_url': 'https://upload.wikimedia.org/wikipedia/en/archive/a/a9/20151112035044!Banyan_Tree_(_Shiv_Bajrang_Dham_Kishunpur).jpeg',";
         requestJson += "'thumb_url': 'https://upload.wikimedia.org/wikipedia/en/archive/a/a9/20151112035044!Banyan_Tree_(_Shiv_Bajrang_Dham_Kishunpur).jpeg',";
         requestJson += "'reply_markup': {";
         requestJson += "'inline_keyboard': [";
         requestJson += "[";
         requestJson += "{";
         requestJson += "'text': 'Click On Me',";
         requestJson += "'callback_data': 'Click'";
         requestJson += "}";
         requestJson += "]";
         requestJson += "]";
         requestJson += "}";
         requestJson += "}";
         requestJson += "]";
         requestJson += "}";
         requestJson += "}";
      }
   }
   var reply = activity.CreateReply();
   reply.ChannelData = requestJson;
   await connector.Conversations.ReplyToActivityAsync(reply);
   var response = Request.CreateResponse(HttpStatusCode.OK);
   return response;
}

@dimoibiehg I've enabled additional logging to try to diagnose this issue. Can you give it a try again when you have a chance? Thanks.

@eanders-MS It has been done. Thanks to your response.

@dimoibiehg Ok I see an entry for your latest answerInlineQuery. Telegram is returning Bad Request: QUERY_ID_INVALID. Your value for inline_query_id does appear to be invalid. It has the same value as the reply activity's replyToId field. It is improbable this could ever be valid.

You code above appears to pull the query id from the correct place, but the value I see in the log is obviously not correct.

Note that inline_query_ids are only valid for 15 seconds or so before Telegram expires them.

@eanders-MS I've logged my test inline query too. When getting query from bot framework, activity_id and inline_query_id, which I received, were the same. Therefore, if this similarity is a problem, it's come from the bot framework. am I right?
Also, the first message which I got from telegram, when wrote an inline query as a user, comes in the following image.
bfdebug

Ok, sorry for the confusion. It stemmed from my lack of understanding about how we process Telegram inline queries. The activity's id is indeed set to the incoming query id in this case. Your inline_query_id value is correct after all.

I'm going to try to repro locally.

Ok. Thanks very much. I'm looking forward to hear from you.

Hi @eanders-MS,
Is there any progress on this issue? (a simple sample code which works as an inline bot that consists of a callback button)

Many thanks in advance.

Sincere apologies for the delay in response. I believe you must serialize the JSON of your results value to a string. Please read the documentation for this field here: https://core.telegram.org/bots/api#answerinlinequery

Closing the issue. If you're still having problems please open a new one.

The problem is not solved as you can see in this issue. You can follow the current issue, in the issue.

Was this page helpful?
0 / 5 - 0 ratings