microsoft / botframework-sdk

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

[Telegram] How correctly retrieve the phone number from the message? #3657

Closed verdysh closed 7 years ago

verdysh commented 7 years ago

Bot Info

SDK Platform: .NET SDK Version: 3.9.0.0 Active Channels: Telegram

Issue Description

Hi!

In Telegram it is possible to output 2 special buttons:

(this is done in a similar way https://github.com/Microsoft/BotBuilder/issues/3642)

Message from bot I get in the usual way:

private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
    var message = await result;
...

If user clicks on the button "request_location", coordinates come in the message.Entities property. If user clicks on the button "request_contact", there is no phone number in any special property (message.Text, message.Attachments, message.Entities).

The phone number is only present in the message.ChannelData property with a bunch of other service information:

"contact":
{  
    "phone_number":"...",
    "first_name":"...",
    "last_name":"...",
    "user_id": 123456789
}

How correctly retrieve the phone number?

if(
    String.IsNullOrEmpty(message.Text) &&
    message.Attachments.Count == 0 &&
    message.Entities.Count == 0
    ) {

    // Looking "contact" node in message.ChannelData property
}

Or there is a more elegant solution?

JasonSowers commented 7 years ago

This seems like a reasonable way considering where the data is stored. What are your concerns?

nwhitmont commented 7 years ago

@verdysh Accessing the message.ChannelData property is the correct way of getting this data.

verdysh commented 7 years ago

@JasonSowers, this method seemed too cumbersome to me and I had fears that I was doing something wrong. So I decided to clarify this.

@nwhitmont, thanks!