8

How can I send this text correctly:

$parameters['text'] = 'you must see [example](example.com) or contact with @exmaple_com';

if I don't use "Markdown", telegram don't show the above link if I use "Markdown", telegram can't handle underline.

mitra razmara
  • 745
  • 6
  • 10

2 Answers2

10

you should use backslash scapes to do so:

$parameters['text'] = 'you must see [example](example.com) or contact with @exmaple\\_com';
tashakori
  • 2,331
  • 1
  • 22
  • 29
  • 1
    What can I do if input string is changing to: `$parameters['text'] = 'you must see [example](example.com) or contact with _@exmaple_com_'` @example_com <- want in italic formating – Max T Oct 30 '17 at 11:03
  • @MaximTronenko Have you solved your problem? Cursive string with underline inside? – parsecer Sep 10 '19 at 20:46
  • @parsecer It's only using HTML parse_mode: '@example_com' ‍♂️ – Max T Sep 25 '19 at 19:57
0

When you set your parse_mode on Markdown or MarkdownV2, you can't use these characters directly: ()._-

You should escape them using backslash,

Also, you should escape backslash itself. for example, in Golang I wrote this function to solve my problem:

func FmtTelegram(input string) string {
  return strings.NewReplacer(
    "(", "\\(", // ()_-. are reserved by telegram.
    ")", "\\)",
    "_", "\\_",
    ".", "\\.",
    "-", "\\-",
  ).Replace(input)
}

And in PHP you should escape like this:

$parameters['text'] = '\\_com';
# or
$parameters['text'] = '\\.com';
# or
$parameters['text'] = '\\-com';
# or
$parameters['text'] = '\\(com\\)';
Arsham Arya
  • 1,461
  • 3
  • 17
  • 25