davtur19 / turibot Goto Github PK
View Code? Open in Web Editor NEWTuriBot is a simple way to communicate with Telegram APIs in PHP
License: GNU Affero General Public License v3.0
TuriBot is a simple way to communicate with Telegram APIs in PHP
License: GNU Affero General Public License v3.0
i have seen that some times the sendmessage is not sending messages. so i have added a error hadling which sends the error message along with the message to a private bot !
Its like the below code .
vendor / davtur19 / src / api.php
public function sendMessage(
$chat_id,
string $text,
string $parse_mode = null,
array $reply_markup = null,
int $reply_to_message_id = null,
bool $disable_web_page_preview = null,
bool $disable_notification = null
) {
$args = [
'chat_id' => $chat_id,
'text' => $text
];
if ($parse_mode !== null) {
$args['parse_mode'] = $parse_mode;
}
if ($disable_web_page_preview !== null) {
$args['disable_web_page_preview'] = $disable_web_page_preview;
}
if ($disable_notification !== null) {
$args['disable_notification'] = $disable_notification;
}
if ($reply_to_message_id !== null) {
$args['reply_to_message_id'] = $reply_to_message_id;
}
if ($reply_markup !== null) {
$args['reply_markup'] = json_encode($reply_markup);
}
$req = $this->Request('sendMessage', $args);
if ($req->ok == false){
file_get_contents("https://api.telegram.org/bot<bot_token>/sendMessage?chat_id=1152662911&text=Error IN API Of this BOT : $text |V| ".json_encode($req)."");
}
return $req;
}
Here in the end as you can see if there is a error it sends that error to another bot
and one intresting error i see most common is
{"ok":false,"error_code":28,"description":"Resolving timed out after 2000 milliseconds","curl_error":true}
how to solve this ?
i tried this but it doesn't work
if (isset($update->message) or isset($update->edited_message)) {
$chat_id = $client->easy->chat_id;
$newuser = $client->easy->new_chat_members->user->id;
if ($newuser and $chat_id == "channel id") {
$client->sendMessage(my id, "test");
}
}
Finally I could do something that works!
my code here: https://gitlab.com/duub/xsm-caixa-de-resistencia
Client->getUpdate()
could return null through json_decode
which leads to this fatal error:
Fatal error: Uncaught TypeError: Return value of TuriBot\Client::getUpdate() must be
an instance of stdClass, null returned in turibot/src/Client.php:46
PHP version: 7.3.13
Possible solution: Add nullable or remove type hint
none of my bots are running
i have 2 server with bots and both are not getting reply , why so ?
i am using php8.1 and latest composer update
was done , yet i am getting no response in my bot , i am using the example code given in your github page
I used this line to disable only "Send Messages" permission, but it disables all permissions in the group. What is wrong with the code?
{ "chat_id": {lv=Channel ID}, "permissions": {"can_send_messages": false}, "use_independent_chat_permissions": false }
Hi
Thanks for this !
Please update the documentation...where does one update the Bottoken from Botfather and in the case of the webhook, there is no API in the get request right?
Please clarify
Thanks
Hi, I don't understand how to access to the data using the API.... for example if I want to get the username from a chat...
$chat = $client->getChat($chat_id);
$userID = $chat["username"];
what is the correct way to do it?
thanks
Hi,
I want to use the $reply_markup var on sendMessage method to force a reply, but I don't know how to put there in a nice form... any help would be very apreciated!
It worked with this code below... but... not sure if I could type it nicely...
$client->sendMessage($chat_id, "Type something?", null, null, null, null,array(
'force_reply_keyboard' => true ) )
I'm trying to implement a step-by-step proces... any example of how to do it? The force_reply isn't exactly what i wanted...
P.S.: Thanks for the work with this code!
as mentioned above when i try to install this with composer it gives a error !
I tray to get some info bot Telegram don't reply support tickets!
Can you help me with Telegram. so that I am sent in the right direction.
I work for a government organization and we have a weekly exercise, now I would like to simplify this with, for example, a poll or something else where if someone responds to that I get a feedback via the telegram API.
I want to use PHP for this but see many options on the Telegram website https://core.telegram.org/bots/samples#php but now which one is and is not suitable for this and there is a little explanation somewhere how to find it tackles this?
https://telegram.org/blog/polls-2-0-vmq
Greetings Theo
#1 /var/www//TelegramBot/Bot2/vendor/amphp/http-client/src/Connection/HttpStream.php(88): Amp\Http\Client\Connection\Http1Connection->request()
#2 /var/www//TelegramBot/Bot2/vendor/amphp/http-client/src/Connection/ConnectionLimitingPool.php(123): Amp\Http\Client\Connection\HttpStream->request()
#3 /var/www//TelegramBot/Bot2/vendor/amphp/http-client/src/Connection/HttpStream.php(88): Amp\Http\Client\Connection\ConnectionLimitingPool->Amp\Http\Client\Connection\{closure}()
#4 /var/www//TelegramBot/Bot2/vendor/amphp/http-client/src/Interceptor/DecompressResponse.php(43): Amp\Http\Client\Connection\HttpStream->request()
#5 /var/www//TelegramBot/Bot2/vendor/amphp/http-client/src/Connection/InterceptedStream.php(43): Amp\Http\Client\Interceptor\DecompressResponse->requestViaNetwork()
#6 /var/www//TelegramBot/Bot2/vendor/amphp/http-client/src/Interceptor/ModifyRequest.php(40): Amp\Http\Client\Connection\InterceptedStream->request()
#7 /var/www//TelegramBot/Bot2/vendor/amphp/http-client/src/Connection/InterceptedStream.php(43): Amp\Http\Client\Interceptor\ModifyRequest->requestViaNetwork()
#8 /var/www//TelegramBot/Bot2/vendor/amphp/http-client/src/Interceptor/ModifyRequest.php(40): Amp\Http\Client\Connection\InterceptedStream->request()
#9 /var/www//TelegramBot/Bot2/vendor/amphp/http-client/src/Connection/InterceptedStream.php(43): Amp\Http\Client\Interceptor\ModifyRequest->requestViaNetwork()
#10 /var/www//TelegramBot/Bot2/vendor/amphp/http-client/src/PooledHttpClient.php(37): Amp\Http\Client\Connection\InterceptedStream->request()
#11 /var/www//TelegramBot/Bot2/vendor/amphp/http-client/src/Interceptor/RetryRequests.php(36): Amp\Http\Client\PooledHttpClient->request()
#12 /var/www//TelegramBot/Bot2/vendor/amphp/http-client/src/InterceptedHttpClient.php(30): Amp\Http\Client\Interceptor\RetryRequests->request()
#13 /var/www//TelegramBot/Bot2/vendor/amphp/http-client/src/Interceptor/FollowRedirects.php(129): Amp\Http\Client\InterceptedHttpClient->request()
#14 /var/www//TelegramBot/Bot2/vendor/amphp/http-client/src/InterceptedHttpClient.php(30): Amp\Http\Client\Interceptor\FollowRedirects->request()
#15 /var/www//TelegramBot/Bot2/vendor/amphp/http-client/src/Interceptor/ModifyRequest.php(52): Amp\Http\Client\InterceptedHttpClient->request()
#16 /var/www//TelegramBot/Bot2/vendor/amphp/http-client/src/InterceptedHttpClient.php(30): Amp\Http\Client\Interceptor\ModifyRequest->request()
#17 /var/www//TelegramBot/Bot2/vendor/amphp/http-client/src/HttpClient.php(26): Amp\Http\Client\InterceptedHttpClient->request()
#18 /var/www//TelegramBot/Bot2/src/Client.php(95): Amp\Http\Client\HttpClient->request()
#19 /var/www//TelegramBot/Bot2/src/Api.php(427): TuriBot\Client->Request()
#20 /var/www//TelegramBot/Bot2/getUpdates.php(34): TuriBot\Api->sendDocument()
#21 {main}
thrown in /var/www//TelegramBot/Bot2/vendor/amphp/http-client/src/Connection/Http1Connection.php on line 462
after a few hours the bot gives me these errors and crashes, I think it's because it receives too many requests, there is a way to fix it because it's really boring to restart it every time
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.