Skip to content

Sending messages

Kyle2142 edited this page Jun 20, 2018 · 2 revisions

One of the real basics of any bot, it needs to interact with people!

Sending messages is easy:

$bot->sendMessage(12345678, "Hello!"); //using ID
$bot->sendMessage('@my_awesome_channel', "Hey everyone!"); //using @channelname (NB: only for channels/supergroups, not users!)

Sending options are passed as a 3rd parameter, an associative array of 'option'=>'value'.

Formatting can make your messages more fancy: Be sure to check out Markdown and HTML reference for bots

$bot->sendMessage(12345678, "Here is some *bold*, _italics_, `code` and a ```code block``` 
                             using Markdown!"); //markdown is default

$bot->sendMessage(12345678, "<i>italics</i>\n<b>bold</b> etc", ['parse_mode'=>'html']); //using HTML

When sending links, you may want to disable the link preview:

$bot->sendMessage(12345678, '[Click me!](example.com)', ['parse_mode'=>'markdown', 'disable_web_page_preview'=>true]);

Be sure to check SendMessage docs for a full list of stuff you can do!