TelegramBot / Api

Native PHP Wrapper for Telegram BOT API
MIT License
1.07k stars 324 forks source link

How to send message to channel using this bot? #300

Closed eizil closed 3 years ago

eizil commented 3 years ago

Hi,

i would like to send auto message to my public channel.

but when I use the channel chat ID (username), it causing error chat not found.

I can send the update normally if using telegram bot url.

How can I achieve this using this bot api class?

Thanks

MyZik commented 3 years ago

Check if your bot has access to sent messages in your channel / group. The bot user has to be an admin.

eizil commented 3 years ago

Check if your bot has access to sent messages in your channel / group. The bot user has to be an admin.

the bot does have access, when I try using direct api.telegram.org url via file_get_contents. it works.

but when I try to use the telegram bot api class. the error occured.

Any idea why?

MyZik commented 3 years ago

Show your response, and your error please

eizil commented 3 years ago

Show your response, and your error please

this is the error log

AH01071: Got error 'PHP message: PHP Fatal error: Uncaught TelegramBot\\Api\\HttpException: Bad Request: chat not found in /home/dev/vendor/telegram-bot/api/src/BotApi.php:284\nStack trace:\n#0 /home/dev/vendor/telegram-bot/api/src/BotApi.php(261): TelegramBot\\Api\\BotApi::curlValidate()\n#1 /home/dev/vendor/telegram-bot/api/src/BotApi.php(230): TelegramBot\\Api\\BotApi->executeCurl()\n#2 /home/dev/vendor/telegram-bot/api/src/BotApi.php(340): TelegramBot\\Api\\BotApi->call()\n#3 [internal function]: TelegramBot\\Api\\BotApi->sendMessage()\n#4 /home/dev/vendor/telegram-bot/api/src/Client.php(405): call_user_func_array()\n#5 /home/dev/bursa-email-reader.php(44): TelegramBot\\Api\\Client->__call()\n#6 {main}\n thrown in /home/dev/vendor/telegram-bot/api/src/BotApi.php on line 284'

MyZik commented 3 years ago

Your chat id is wrong

eizil commented 3 years ago

Your chat id is wrong

that's the problem, I use the same chat ID to update using the direct bot api.telegram url, its working properly.

why when using the telegram api class, that error occured?

tried both using channel username and channel ID number, both give out same error.

MyZik commented 3 years ago

So I think the error is pretty clear. Something is wrong with the channel ID or with the bot rights. I don't have any idea. Can you please show your send message code?