Messages
Messages can be sent to a Telegram chat using a TelegraphChat
model
use DefStudio\Telegraph\Models\TelegraphChat; $chat = TelegraphChat::find(44); // this will use the default parsing method set in config/telegraph.php $chat->message('hello')->send(); $chat->html("<b>hello</b>\n\nI'm a bot!")->send(); $chat->markdown('*hello*')->send();
Options
Telegraph allows sending complex messages by setting some options:
edit
Updates an existing message instead of sending a new one
$chat->edit(123456)->message("new text")->send();
reply
The message can be sent as a reply by setting the original message ID
$chat->message("ok!")->reply(123456)->send();
forceReply
Forces the user to reply to the message. For more information see the official api documentation
$chat->message("ok!")->forceReply(placeholder: 'Enter your reply...')->send();
forwardMessage
Use this method to forward messages of any kind.
$chat->forwardMessage($fromChat,$messageId)->send();
copyMessage
Use this method to copy messages of any kind. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message.
$chat->copyMessage($fromChat,$messageId)->send();
protected
Protects message contents from forwarding and saving
$chat->message("please don't share this")->protected()->send();
silent
Sends the message silently. Users will receive a notification with no sound.
$chat->message("late night message")->silent()->send();
withoutPreview
Disables link previews for links in this message
$chat->message("http://my-blog.dev")->withoutPreview()->send();
Deletions
Delete a message
The ->deleteMessage()
Telegraph method allows to remove a message from a chat/group/channel.
WarningA message can be deleted if it was sent less than 48h ago and if it was sent by the bot or if the bot has permission to delete other users' messages.
Delete multiple messages
The ->deleteMessages()
Telegraph method allows to delete multiple messages from a chat/group/channel simultaneously. If some of the specified messages can't be found, they are skipped. Identifiers of 1-100 messages to delete.