microsoft / botframework-sdk

Bot Framework provides the most comprehensive experience for building conversation applications.
MIT License
7.48k stars 2.44k forks source link

Activity from Telegram group chat contains no mentions #2539

Closed matthewz0584 closed 6 years ago

matthewz0584 commented 7 years ago

The activities from group chat on Telegram channel contain no mention objects (GetMentions method) although the users are mentioned. Here is the log from some message activity (command to bot - the way for the bot to receive the message). There are mentions (text_mentions?) in channelData, but not in the collection returned by GetMentions, which strangely returns only the bot instead:

/hi Андрей Матвей

Activity:


{
  "type": "message",
  "id": "IXNy2KlM2WV",
  "timestamp": "2017-04-03T15:13:05.0542577Z",
  "serviceUrl": "https://telegram.botframework.com",
  "channelId": "telegram",
  "from": {
    "id": "354557895"
  },
  "conversation": {
    "isGroup": true,
    "id": "-208483668",
    "name": "bot debug"
  },
  "recipient": {
    "id": "egorngrok1bot",
    "name": "ngroklocal"
  },
  "text": "/hi Андрей Матвей",
  "entities": [
    {
      "type": "mention",
      "mentioned": {
        "id": "egorngrok1bot",
        "name": "ngroklocal"
      },
      "text": "egorngrok1bot"
    }
  ],
  "channelData": {
    "update_id": 324971640,
    "message": {
      "message_id": 32,
      "from": {
        "id": 354557895,
        "first_name": "Sergey",
        "last_name": "Knyazev"
      },
      "chat": {
        "id": -208483668,
        "title": "bot debug",
        "type": "group",
        "all_members_are_administrators": true
      },
      "date": 1491232365,
      "text": "/hi Андрей Матвей",
      "entities": [
        {
          "type": "bot_command",
          "offset": 0,
          "length": 3
        },
        {
          "type": "text_mention",
          "offset": 4,
          "length": 6,
          "user": {
            "id": 345018769,
            "first_name": "Andrey"
          }
        },
        {
          "type": "text_mention",
          "offset": 11,
          "length": 6,
          "user": {
            "id": 370536472,
            "first_name": "Matvei",
            "last_name": "Stepanov"
          }
        }
      ]
    }
  }
}
``

GetMentions():
`[
  {
    "mentioned": {
      "id": "egorngrok1bot",
      "name": "ngroklocal"
    },
    "text": "egorngrok1bot",
    "type": "mention"
  }
]
`

To compare, here is the log from Skype channel:

**@NGrok Say hi to @Andrey D**

Activity:
`{
  "text": "<at id=\"28:a72df016-6716-4f39-8cf2-08c61e5340a4\">@NGrok</at> Say hi to <at id=\"live:dronishe\">@Andrey D</at>",
  "entities": [
    {
      "type": "mention",
      "mentioned": {
        "id": "28:a72df016-6716-4f39-8cf2-08c61e5340a4"
      },
      "text": "<at id=\"28:a72df016-6716-4f39-8cf2-08c61e5340a4\">@NGrok</at>"
    },
    {
      "type": "mention",
      "mentioned": {
        "id": "live:dronishe"
      },
      "text": "<at id=\"live:dronishe\">@Andrey D</at>"
    },
    {
      "type": "clientInfo",
      "locale": "en"
    }
  ]
}
`

GetMentions():
`
[
  {
    "mentioned": {
      "id": "28:a72df016-6716-4f39-8cf2-08c61e5340a4"
    },
    "text": "<at id=\"28:a72df016-6716-4f39-8cf2-08c61e5340a4\">@NGrok</at>",
    "type": "mention"
  },
  {
    "mentioned": {
      "id": "live:dronishe"
    },
    "text": "<at id=\"live:dronishe\">@Andrey D</at>",
    "type": "mention"
  }
]
`

Is there a way to make GetMentions method return mentions from Telegram channel?
nwhitmont commented 7 years ago

hi @matthewz0584 - can you provide more details about your issue?

Environment

Issue

What the issue is, in broad strokes. Link to Stack Overflow post.

Example Code

The code snippet or complete bot example (preferred) that demonstrates the issue.

Steps to Reproduce

Please provide the shortest amount of steps to reproduce your issue.

Expected Behavior

What you expected to happen.

Actual Results

What actually happened. Please give examples and support it with screenshots, copied output or error messages.

matthewz0584 commented 7 years ago

OS: Windows 7 x64 SDK: C#/.Net 4.6 Dev environment: Azure Web App

Issue Activity.GetMentions() for activity originated from Telegram channel group chat returns wrong Mentions array: mentioned users are not there, not mentioned bot is there.

Code

    [BotAuthentication]
    public class MessagesController : ApiController
    {
        [ResponseType(typeof(void))]
        public virtual async Task<HttpResponseMessage> Post([FromBody] Activity activity)
        {
            if (activity != null)
            {
                var activityAsJson = JsonConvert.SerializeObject(activity);
                var mentionsAsJson = JsonConvert.SerializeObject(activity.GetMentions());
            }
            return new HttpResponseMessage(HttpStatusCode.Accepted);
        }
    }

Steps to reproduce In order for the bot to receive the message at all in Telegram we use / symbol which denotes a command to bot. The message we send is (two users are mentioned, and in Telegram mentioned users are in bold font): /hi Андрей Матвей

Expected Behavior Given that, I expect Activity.GetMentions to return correctly filled Mention array, i.e array with two mentions for two mentioned users. Which is quite true for the similar fixture on the Skype channel (the dump of such Activity is given in original issue for reference).

Actual results The bot receives corresponding Activity, its dump is given in original issue, but the GetMentions() method returns only one mention for the bot, while the trully mentioned users could only be found as "text_mentions" in ChannelData property.

JasonSowers commented 7 years ago

@matthewz0584 are you still experiencing the same issue?

matthewz0584 commented 7 years ago

Yep, I am. Recent Bot framework update has fixed some issues (Activity.GetMentions throwing StackOverflowException, for example), but, alas, not mine.

Fresh dump with no mentions in Entities property and two text_mention in ChannelData:

"entities": [ { "type": "mention", "mentioned": { "id": "egorbotbot", "name": "egorkabot" }, "text": "egorbotbot" } ], "channelData": { ... "entities": [ { "type": "text_mention", "offset": 1, "length": 6, "user": { "id": 354557895, "first_name": "Sergey", "last_name": "Knyazev" } }, { "type": "text_mention", "offset": 8, "length": 6, "user": { "id": 345018769, "first_name": "Andrey" } } ] }

For now, we parse ChannelData, but I have no idea, why it is not parsed by framework.

nwhitmont commented 6 years ago

open a new issue if further questions

absinghal commented 4 years ago

Just want to put on record that facing exactly the same issue even in Bot framework 4.0.