skip to Main Content

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.

2

Answers


  1. you should use backslash scapes to do so:

    $parameters['text'] = 'you must see [example](example.com) or contact with @exmaple\_com';
    
    Login or Signup to reply.
  2. 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\)';
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search