本文整理汇总了PHP中Longman\TelegramBot\Request::sendMessage方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::sendMessage方法的具体用法?PHP Request::sendMessage怎么用?PHP Request::sendMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Longman\TelegramBot\Request
的用法示例。
在下文中一共展示了Request::sendMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute()
{
$update = $this->getUpdate();
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$message_id = $message->getMessageId();
$text = $message->getText(true);
if (empty($text)) {
$text_back = 'Write the message to sent: /sendtochannel <message>';
} else {
$your_channel = $this->getConfig('your_channel');
//Send message to channel
$data = [];
$data['chat_id'] = $your_channel;
$data['text'] = $text;
$result = Request::sendMessage($data);
if ($result->isOk()) {
$text_back = 'Message sent succesfully to: ' . $your_channel;
} else {
$text_back = 'Sorry message not sent to: ' . $your_channel;
}
}
$data = [];
$data['chat_id'] = $chat_id;
$data['text'] = $text_back;
$result = Request::sendMessage($data);
return $result;
}
示例2: execute
/**
* {@inheritdoc}
*/
public function execute()
{
$message = $this->getMessage();
$message_id = $message->getMessageId();
$chat_id = $message->getChat()->getId();
$text = $message->getText(true);
if (empty($text)) {
$text = 'You must specify timezone in format: /time <timezone>
timezone list ->
EET = UTC+2
UTC = UTC
PRC = PRC --- UTC+8
CET = UTC+1
';
} else {
$tz = $this->IsTimeZone($text, $timezone);
if (empty($tz)) {
date_default_timezone_set('PRC');
$text = strftime("Time is %F %H:%M:%S", time());
} else {
date_default_timezone_set($tz);
$text = strftime("Time is %F %H:%M:%S", time());
}
}
$data = ['chat_id' => $chat_id, 'disable_notification' => false, 'reply_to_message_id' => $message_id, 'text' => $text];
return Request::sendMessage($data);
}
示例3: execute
/**
* {@inheritdoc}
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$message_id = $message->getMessageId();
$command = trim($message->getText(true));
//Only get enabled Admin and User commands
$commands = array_filter($this->telegram->getCommandsList(), function ($command) {
return !$command->isSystemCommand() && $command->isEnabled();
});
//If no command parameter is passed, show the list
if ($command === '') {
$text = $this->telegram->getBotName() . ' v. ' . $this->telegram->getVersion() . "\n\n";
$text .= 'Commands List:' . "\n";
foreach ($commands as $command) {
$text .= '/' . $command->getName() . ' - ' . $command->getDescription() . "\n";
}
$text .= "\n" . 'For exact command help type: /help <command>';
} else {
$command = str_replace('/', '', $command);
if (isset($commands[$command])) {
$command = $commands[$command];
$text = 'Command: ' . $command->getName() . ' v' . $command->getVersion() . "\n";
$text .= 'Description: ' . $command->getDescription() . "\n";
$text .= 'Usage: ' . $command->getUsage();
} else {
$text = 'No help available: Command /' . $command . ' not found';
}
}
$data = ['chat_id' => $chat_id, 'reply_to_message_id' => $message_id, 'text' => $text];
return Request::sendMessage($data);
}
示例4: execute
/**
* {@inheritdoc}
*/
public function execute()
{
$message = $this->getMessage();
$inline_keyboard = [new InlineKeyboardButton(['text' => 'inline', 'switch_inline_query' => 'true']), new InlineKeyboardButton(['text' => 'callback', 'callback_data' => 'identifier']), new InlineKeyboardButton(['text' => 'open url', 'url' => 'https://github.com/akalongman/php-telegram-bot'])];
$data = ['chat_id' => $message->getChat()->getId(), 'text' => 'inline keyboard', 'reply_markup' => new InlineKeyboardMarkup(['inline_keyboard' => [$inline_keyboard]])];
return Request::sendMessage($data);
}
示例5: execute
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$message_id = $message->getMessageId();
$command = trim($message->getText(true));
//Only get enabled Admin and User commands
/** @var Command[] $command_objs */
$command_objs = array_filter($this->telegram->getCommandsList(), function ($command_obj) {
/** @var Command $command_obj */
return !$command_obj->isSystemCommand() && $command_obj->isEnabled();
});
//If no command parameter is passed, show the list
if ($command === '') {
$text = sprintf('%s v. %s' . PHP_EOL . PHP_EOL . 'Commands List:' . PHP_EOL, $this->telegram->getBotName(), $this->telegram->getVersion());
foreach ($command_objs as $command) {
$text .= sprintf('/%s - %s' . PHP_EOL, $command->getName(), $command->getDescription());
}
$text .= PHP_EOL . 'For exact command help type: /help <command>';
} else {
$command = str_replace('/', '', $command);
if (isset($command_objs[$command])) {
/** @var Command $command_obj */
$command_obj = $command_objs[$command];
$text = sprintf('Command: %s v%s' . PHP_EOL . 'Description: %s' . PHP_EOL . 'Usage: %s', $command_obj->getName(), $command_obj->getVersion(), $command_obj->getDescription(), $command_obj->getUsage());
} else {
$text = 'No help available: Command /' . $command . ' not found';
}
}
$data = ['chat_id' => $chat_id, 'reply_to_message_id' => $message_id, 'text' => $text];
return Request::sendMessage($data);
}
示例6: execute
/**
* {@inheritdoc}
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$text = $message->getText(true);
$data = [];
$data['chat_id'] = $chat_id;
$data['text'] = 'Press a Button:';
//Keyboard examples
$inline_keyboards = [];
//0
$inline_keyboard[] = [['text' => '<', 'callback_data' => 'go_left'], ['text' => '^', 'callback_data' => 'go_up'], ['text' => '>', 'callback_data' => 'go_right']];
$inline_keyboards[] = $inline_keyboard;
unset($inline_keyboard);
//1
$inline_keyboard[] = [['text' => 'open google.com', 'url' => 'google.com'], ['text' => 'open youtube.com', 'url' => 'youtube.com']];
$inline_keyboards[] = $inline_keyboard;
unset($inline_keyboard);
//2
$inline_keyboard[] = [['text' => 'search \'test\' inline', 'switch_inline_query' => 'test'], ['text' => 'search \'cats\' inline', 'switch_inline_query' => 'cats']];
$inline_keyboard[] = [['text' => 'search \'earth\' inline', 'switch_inline_query' => 'earth']];
$inline_keyboards[] = $inline_keyboard;
unset($inline_keyboard);
//3
$inline_keyboard[] = [['text' => 'open url', 'url' => 'https://github.com/akalongman/php-telegram-bot']];
$inline_keyboard[] = [['text' => 'switch to inline', 'switch_inline_query' => 'thumb up']];
$inline_keyboard[] = [['text' => 'send callback query', 'callback_data' => 'thumb up'], ['text' => 'send callback query (no alert)', 'callback_data' => 'thumb down']];
$inline_keyboards[] = $inline_keyboard;
unset($inline_keyboard);
$data['reply_markup'] = new InlineKeyboardMarkup(['inline_keyboard' => $inline_keyboards[3]]);
return Request::sendMessage($data);
}
示例7: execute
/**
* {@inheritdoc}
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$data = ['chat_id' => $chat_id, 'text' => 'Keyboard Hidden', 'reply_markup' => new ReplyKeyboardHide(['selective' => false])];
return Request::sendMessage($data);
}
示例8: execute
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$text = 'Hi there!' . PHP_EOL . 'Type /help to see all commands!';
$data = ['chat_id' => $chat_id, 'text' => $text];
return Request::sendMessage($data);
}
示例9: execute
/**
* {@inheritdoc}
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$data = [];
$data['chat_id'] = $chat_id;
$data['text'] = 'Write something:';
$data['reply_markup'] = new ForceReply(['selective' => false]);
return Request::sendMessage($data);
}
示例10: execute
/**
* {@inheritdoc}
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$text = $message->getText(true);
$data = [];
$data['chat_id'] = $chat_id;
$data['parse_mode'] = 'MARKDOWN';
$data['text'] = "*bold* _italic_ `inline fixed width code` ```preformatted code block\ncode block\n```\n[Best Telegram bot api!!](https://github.com/akalongman/php-telegram-bot)\n\n";
return Request::sendMessage($data);
}
示例11: execute
/**
* {@inheritdoc}
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$text = trim($message->getText(true));
if ($text === '') {
$text = 'Command usage: ' . $this->getUsage();
}
$data = ['chat_id' => $chat_id, 'text' => $text];
return Request::sendMessage($data);
}
示例12: execute
public function execute()
{
$update = $this->getUpdate();
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$text = $message->getText(true);
$data = array();
$data['chat_id'] = $chat_id;
$data['text'] = $text;
$result = Request::sendMessage($data);
}
示例13: execute
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$member = $message->getNewChatMember();
$text = 'Hi there!';
if (!$message->botAddedInChat()) {
$text = 'Hi ' . $member->tryMention() . '!';
}
$data = ['chat_id' => $chat_id, 'text' => $text];
return Request::sendMessage($data);
}
示例14: execute
public function execute()
{
$update = $this->getUpdate();
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
//$text = $message->getText(true);
$data = array();
$data['chat_id'] = $chat_id;
$data['text'] = "Ciao dal tuo bot...";
$result = Request::sendMessage($data);
return $result;
}
示例15: execute
public function execute()
{
$update = $this->getUpdate();
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$data = array();
$data['chat_id'] = $chat_id;
$text = "Hi there!\nType /help to see all commands!";
$data['text'] = $text;
$result = Request::sendMessage($data);
return $result;
}