Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to send message outside webhooks? #1435

Closed
nightrider77 opened this issue Nov 30, 2023 · 1 comment
Closed

How to send message outside webhooks? #1435

nightrider77 opened this issue Nov 30, 2023 · 1 comment
Labels

Comments

@nightrider77
Copy link

nightrider77 commented Nov 30, 2023

require_once("./vendor/autoload.php");
$bot_api_key  = ':';
$bot_username = '';
try {
   $bot = new Longman\TelegramBot\Telegram($bot_api_key, $bot_username);
   ..... ? // $bot->sendMessage($user['telegram_chatId'], $messageText);
}

If I just execute sendMessage on $bot, I will get error

Fatal error: Uncaught Error: Call to undefined method Longman\TelegramBot\Telegram::sendMessage()

Why there is no information on how to deal with this without any webhooks, e.g. if you just need to notify website users with some information.

Thanks.

@nightrider77
Copy link
Author

I will reply to myself. But it's very strange there is no simple method to send a simple message...
The lack of information in the readme.md is also very strange.

use Longman\TelegramBot\Request; 
require_once("./vendor/autoload.php");
$bot_api_key  = ':';
$bot_username = '';
try {
   $bot = new Longman\TelegramBot\Telegram($bot_api_key, $bot_username);
   $result = Request::sendMessage([
        'chat_id' => $user['telegram_chatId'],
        'text'    => $messageText,
   ]);
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
  // log telegram errors
  // echo $e->getMessage();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant