Commit 6ce3f10d authored by Armando Lüscher's avatar Armando Lüscher Committed by GitHub

Merge pull request #358 from jacklul/channel_posts

Add support for channel_post and edited_channel_post
parents 4b2edc59 f84647e1
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
/**
* Channel post command
*/
class ChannelpostCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'Channelpost';
/**
* @var string
*/
protected $description = 'Handle channel post';
/**
* @var string
*/
protected $version = '1.0.0';
/**
* Execute command
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
//$channel_post = $this->getChannelPost();
return parent::execute();
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
/**
* Edited channel post command
*/
class EditedchannelpostCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'Editedchannelpost';
/**
* @var string
*/
protected $description = 'Handle edited channel post';
/**
* @var string
*/
protected $version = '1.0.0';
/**
* Execute command
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
//$edited_channel_post = $this->getEditedChannelPost();
return parent::execute();
}
}
...@@ -466,6 +466,49 @@ class DB ...@@ -466,6 +466,49 @@ class DB
return self::insertTelegramUpdate($update_id, $chat_id, $message_id, null, null, null, null); return self::insertTelegramUpdate($update_id, $chat_id, $message_id, null, null, null, null);
} }
} elseif ($update_type === 'edited_message') {
$edited_message = $update->getEditedMessage();
if (self::insertEditedMessageRequest($edited_message)) {
$chat_id = $edited_message->getChat()->getId();
$edited_message_local_id = self::$pdo->lastInsertId();
return self::insertTelegramUpdate(
$update_id,
$chat_id,
null,
null,
null,
null,
$edited_message_local_id
);
}
} else if ($update_type === 'channel_post') {
$channel_post = $update->getChannelPost();
if (self::insertMessageRequest($channel_post)) {
$message_id = $channel_post->getMessageId();
$chat_id = $channel_post->getChat()->getId();
return self::insertTelegramUpdate($update_id, $chat_id, $message_id, null, null, null, null);
}
} elseif ($update_type === 'edited_channel_post') {
$edited_channel_post = $update->getEditedChannelPost();
if (self::insertEditedMessageRequest($edited_channel_post)) {
$chat_id = $edited_channel_post->getChat()->getId();
$edited_channel_post_local_id = self::$pdo->lastInsertId();
return self::insertTelegramUpdate(
$update_id,
$chat_id,
null,
null,
null,
null,
$edited_channel_post_local_id
);
}
} elseif ($update_type === 'inline_query') { } elseif ($update_type === 'inline_query') {
$inline_query = $update->getInlineQuery(); $inline_query = $update->getInlineQuery();
...@@ -498,23 +541,6 @@ class DB ...@@ -498,23 +541,6 @@ class DB
return self::insertTelegramUpdate($update_id, null, null, null, null, $callback_query_id, null); return self::insertTelegramUpdate($update_id, null, null, null, null, $callback_query_id, null);
} }
} elseif ($update_type === 'edited_message') {
$edited_message = $update->getEditedMessage();
if (self::insertEditedMessageRequest($edited_message)) {
$chat_id = $edited_message->getChat()->getId();
$edited_message_local_id = self::$pdo->lastInsertId();
return self::insertTelegramUpdate(
$update_id,
$chat_id,
null,
null,
null,
null,
$edited_message_local_id
);
}
} }
return false; return false;
......
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
/**
* {@inheritdoc}
*/
class ChannelPost extends Message
{
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
/**
* {@inheritdoc}
*/
class EditedChannelPost extends Message
{
}
...@@ -18,6 +18,8 @@ namespace Longman\TelegramBot\Entities; ...@@ -18,6 +18,8 @@ namespace Longman\TelegramBot\Entities;
* @method int getUpdateId() The update's unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if you’re using Webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order. * @method int getUpdateId() The update's unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if you’re using Webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order.
* @method Message getMessage() Optional. New incoming message of any kind — text, photo, sticker, etc. * @method Message getMessage() Optional. New incoming message of any kind — text, photo, sticker, etc.
* @method Message getEditedMessage() Optional. New version of a message that is known to the bot and was edited * @method Message getEditedMessage() Optional. New version of a message that is known to the bot and was edited
* @method Message getChannelPost() Optional. New post in the channel, can be any kind — text, photo, sticker, etc.
* @method Message getEditedChannelPost() Optional. New version of a post in the channel that is known to the bot and was edited
* @method InlineQuery getInlineQuery() Optional. New incoming inline query * @method InlineQuery getInlineQuery() Optional. New incoming inline query
* @method ChosenInlineResult getChosenInlineResult() Optional. The result of an inline query that was chosen by a user and sent to their chat partner. * @method ChosenInlineResult getChosenInlineResult() Optional. The result of an inline query that was chosen by a user and sent to their chat partner.
* @method CallbackQuery getCallbackQuery() Optional. New incoming callback query * @method CallbackQuery getCallbackQuery() Optional. New incoming callback query
...@@ -32,6 +34,8 @@ class Update extends Entity ...@@ -32,6 +34,8 @@ class Update extends Entity
return [ return [
'message' => Message::class, 'message' => Message::class,
'edited_message' => EditedMessage::class, 'edited_message' => EditedMessage::class,
'channel_post' => ChannelPost::class,
'edited_channel_post' => EditedChannelPost::class,
'inline_query' => InlineQuery::class, 'inline_query' => InlineQuery::class,
'chosen_inline_result' => ChosenInlineResult::class, 'chosen_inline_result' => ChosenInlineResult::class,
'callback_query' => CallbackQuery::class, 'callback_query' => CallbackQuery::class,
...@@ -48,6 +52,8 @@ class Update extends Entity ...@@ -48,6 +52,8 @@ class Update extends Entity
$types = [ $types = [
'message', 'message',
'edited_message', 'edited_message',
'channel_post',
'edited_channel_post',
'inline_query', 'inline_query',
'chosen_inline_result', 'chosen_inline_result',
'callback_query', 'callback_query',
......
...@@ -394,7 +394,7 @@ class Telegram ...@@ -394,7 +394,7 @@ class Telegram
$command = 'genericmessage'; $command = 'genericmessage';
$update_type = $this->update->getUpdateType(); $update_type = $this->update->getUpdateType();
if (in_array($update_type, ['inline_query', 'chosen_inline_result', 'callback_query', 'edited_message'], true)) { if (in_array($update_type, ['edited_message', 'channel_post', 'edited_channel_post', 'inline_query', 'chosen_inline_result', 'callback_query'], true)) {
$command = $this->getCommandFromType($update_type); $command = $this->getCommandFromType($update_type);
} elseif ($update_type === 'message') { } elseif ($update_type === 'message') {
$message = $this->update->getMessage(); $message = $this->update->getMessage();
...@@ -544,10 +544,12 @@ class Telegram ...@@ -544,10 +544,12 @@ class Telegram
//Try to figure out if the user is an admin //Try to figure out if the user is an admin
$update_methods = [ $update_methods = [
'getMessage', 'getMessage',
'getEditedMessage',
'getChannelPost',
'getEditedChannelPost',
'getInlineQuery', 'getInlineQuery',
'getChosenInlineResult', 'getChosenInlineResult',
'getCallbackQuery', 'getCallbackQuery',
'getEditedMessage',
]; ];
foreach ($update_methods as $update_method) { foreach ($update_methods as $update_method) {
$object = call_user_func([$this->update, $update_method]); $object = call_user_func([$this->update, $update_method]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment