How to make phone number a link in Telegram Bot?
Asked Answered
H

4

10

Our team tries to create the Telegram Bot and it is essential for us to make phone number in the long messages clickable. Sometimes we have to send our users messages with a lot of information and few phone numbers, so it is hard to get the phone, because telegram allows to copy only the whole message. If we send the short message without any markdown the telegram mobile app will highlight it:

await bot.send_message(chat_id, "Example text with a phone +79991234567")

Telegram shows the phone number as a link

If we use Markdown Telegram also make a number be clickable:

await bot.send_message(
    chat_id,
    "Example text with a phone [+79991234567](tel:+79991234567)", 
    parse_mode='Markdown'
)

Telegram shows the phone number as a link

Although if the message is a quite long Telegram just ignore the numbers and don't parse:

await bot.send_message(
    chat_id, 
    "Example text with a phone [+79991234567](tel:+79991234567)\nwithin a long-long message\nwithin a long-long message\nwithin a long-long message\nwithin a long-long message\nwithin a long-long message\nwithin a long-long message\nwithin a long-long message\nwithin a long-long message\nwithin a long-long message\nwithin a long-long message", 
    parse_mode='Markdown'
)

Telegram doesn't shows the phone number as a link

Is there a way to make Telegram to show phone numbers as a link? Thank you

Haletky answered 14/11, 2016 at 14:9 Comment(0)
C
4

I found that when string length is 200 or more, highlighting won't work. Seems like unofficial limitation.

Cholon answered 9/12, 2016 at 5:59 Comment(5)
Yep, and I suppose it is only mobile-clients feature to highlight numbers, so desktop and web apps don't even highlight for any messages at allHaletky
That's right, web and desktop don't highlight messages. I wish this could be better explained in docs. And to be honest, I don't like this kind of magic. Engineer should always know what to expectCholon
It could be observed in code. Here's contributor answers this question. I asked to increase limit to say 800 chars. reddit.com/r/Telegram/comments/5qhfa3/clickable_phone_numberMurchison
Do you know if there is a way to do that, but instead of showing the number, show a text like “here”?Cribble
@JacoboTapia no ideaCholon
S
2

According to Telegram API there's no such thing for showing numbers clickable. Your Telegram application is doing the job and for long messages it doesn't work (maybe open an issue in GitHub and tell them). You can just use HTML or Markdown to change style of phone numbers but they can't be clickable for saving to contacts.

Secularism answered 16/11, 2016 at 0:35 Comment(0)
S
0

You need to prefix country code to get a clickable phone no

Sassanid answered 12/8, 2018 at 15:28 Comment(1)
+7 is the Russia's country code, so I have used the prefix, it didn't helpHaletky
B
0

Even if it's an old question, just notice one point: this is OK on cell version of Telegram but on desktop version (eg Mac OS version in my case), this doesn't create link.

Bamako answered 17/6 at 11:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.