zelenin / telegram-bot-api Goto Github PK
View Code? Open in Web Editor NEWTelegram Bot API Client
License: MIT License
Telegram Bot API Client
License: MIT License
I creat command /usr/bin/php /application/yii telegram/run
But errror
Exception 'GuzzleHttp\Exception\ConnectException' with message 'cURL error 6: Could not resolve host: api.telegram.org (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)'
in .../application/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:186
In readme in "Usage" section you missed a single quote after "Test message". That's why highlighting isn't working there.
$response = $client->sendMessage([
'chat_id' => $chatId,
'text' => 'Test message // <- here you are
]);
Exception 'GuzzleHttp\Exception\ServerException' with message 'Server error: `POST https://api.telegram.org/uuuuuu:iiiiiiiiiiiiii/getUpdates` resulted in a `502 Bad Gateway` response:
<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
(truncated...)
'
in /home/101112.pw/httpdocs/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:107
Stack trace:
#0 /home/101112.pw/httpdocs/vendor/guzzlehttp/guzzle/src/Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response))
#1 /home/101112.pw/httpdocs/vendor/guzzlehttp/promises/src/Promise.php(201): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#2 /home/101112.pw/httpdocs/vendor/guzzlehttp/promises/src/Promise.php(154): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array)
#3 /home/101112.pw/httpdocs/vendor/guzzlehttp/promises/src/TaskQueue.php(61): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()
#4 /home/101112.pw/httpdocs/vendor/guzzlehttp/promises/src/Promise.php(242): GuzzleHttp\Promise\TaskQueue->run(true)
#5 /home/101112.pw/httpdocs/vendor/guzzlehttp/promises/src/Promise.php(219): GuzzleHttp\Promise\Promise->invokeWaitFn()
#6 /home/101112.pw/httpdocs/vendor/guzzlehttp/promises/src/Promise.php(262): GuzzleHttp\Promise\Promise->waitIfPending()
#7 /home/101112.pw/httpdocs/vendor/guzzlehttp/promises/src/Promise.php(221): GuzzleHttp\Promise\Promise->invokeWaitList()
#8 /home/101112.pw/httpdocs/vendor/guzzlehttp/promises/src/Promise.php(62): GuzzleHttp\Promise\Promise->waitIfPending()
#9 /home/101112.pw/httpdocs/vendor/guzzlehttp/guzzle/src/Client.php(129): GuzzleHttp\Promise\Promise->wait()
#10 /home/101112.pw/httpdocs/vendor/guzzlehttp/guzzle/src/Client.php(87): GuzzleHttp\Client->request('post', 'https://api.tel...', Array)
#11 /home/101112.pw/httpdocs/vendor/zelenin/telegram-bot-api/Client.php(50): GuzzleHttp\Client->__call('post', Array)
#12 /home/101112.pw/httpdocs/vendor/zelenin/telegram-bot-api/Client.php(50): GuzzleHttp\Client->post('https://api.tel...', Array)
#13 /home/101112.pw/httpdocs/vendor/zelenin/telegram-bot-api/Api.php(44): Zelenin\Telegram\Bot\Client->request('getUpdates', Array)
#14 /home/101112.pw/httpdocs/vendor/zelenin/telegram-bot-api/Api.php(259): Zelenin\Telegram\Bot\Api->request('getUpdates', Array)
#15 /home/101112.pw/httpdocs/vendor/zelenin/telegram-bot-api/Daemon/Daemon.php(68): Zelenin\Telegram\Bot\Api->getUpdates(Array)
#16 /home/101112.pw/httpdocs/vendor/zelenin/telegram-bot-api/Daemon/Daemon.php(55): Zelenin\Telegram\Bot\Daemon\Daemon::getUpdates()
#17 [internal function]: Zelenin\Telegram\Bot\Daemon\Daemon->Zelenin\Telegram\Bot\Daemon\{closure}('0000000034ef15d...', NULL)
#18 /home/101112.pw/httpdocs/vendor/amphp/amp/lib/NativeReactor.php(288): call_user_func(Object(Closure), '0000000034ef15d...', NULL)
#19 /home/101112.pw/httpdocs/vendor/amphp/amp/lib/NativeReactor.php(221): Amp\NativeReactor->executeTimers()
#20 /home/101112.pw/httpdocs/vendor/amphp/amp/lib/NativeReactor.php(70): Amp\NativeReactor->doTick(false)
#21 /home/101112.pw/httpdocs/vendor/amphp/amp/lib/functions.php(46): Amp\NativeReactor->run(Object(Closure))
#22 /home/101112.pw/httpdocs/vendor/zelenin/telegram-bot-api/Daemon/Daemon.php(60): Amp\run(Object(Closure))
#23 /home/101112.pw/httpdocs/vendor/mirocow/yii2-telegram-api/src/controllers/BotController.php(87): Zelenin\Telegram\Bot\Daemon\Daemon->run()
#24 [internal function]: mirocow\telegram\controllers\BotController->actionIndex()
#25 /home/101112.pw/httpdocs/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array(Array, Array)
#26 /home/101112.pw/httpdocs/vendor/yiisoft/yii2/base/Controller.php(154): yii\base\InlineAction->runWithParams(Array)
#27 /home/101112.pw/httpdocs/vendor/yiisoft/yii2/console/Controller.php(119): yii\base\Controller->runAction('', Array)
#28 /home/101112.pw/httpdocs/vendor/yiisoft/yii2/base/Module.php(454): yii\console\Controller->runAction('', Array)
#29 /home/101112.pw/httpdocs/vendor/yiisoft/yii2/console/Application.php(167): yii\base\Module->runAction('telegram/bot', Array)
#30 /home/101112.pw/httpdocs/vendor/yiisoft/yii2/console/Application.php(143): yii\console\Application->runAction('telegram/bot', Array)
#31 /home/101112.pw/httpdocs/vendor/yiisoft/yii2/base/Application.php(375): yii\console\Application->handleRequest(Object(yii\console\Request))
#32 /home/101112.pw/httpdocs/yii(23): yii\base\Application->run()
#33 {main}
I just get
Client error: 400
hi new line for telegram message send not work
please fix it and or show me other method for send message white new line
thak you ..
this error is on my server logs and repeated
PHP Fatal error: Uncaught Zelenin\Telegram\Bot\Exception\NotOkException: Code: 403. Description: "Bot was blocked by the user". in /app/vendor/zelenin/telegram-bot-api/Api.php:43
and catch is this :
catch (\Zelenin\Telegram\Bot\NotOkException $e) {
$logger->addInfo('catch error:'.$e->getMessage());
}
catch not work and error repeat on server logs
what should I do?
when i use your newest library , this code show me Error server,
But when i use your oldest version , show "Code: 400. Description: "[Error]: Bad Request: chat_id is empty" and works fine !
please help me to work with your newes library !
Code :
require 'vendor/autoload.php';
require 'lib/config.php'
$client = new Zelenin\Telegram\Bot\Api($token); // Set your access token
$update = json_decode(file_get_contents('php://input'));
try {
$test = 'dgd';
$response = $client->sendMessage([
'chat_id' => $update->message->chat->id,
'text' => $test
]);
} catch (\Zelenin\Telegram\Bot\NotOkException $e) {
echo $e->getMessage();
}
hi
first I want to thank for this nice library.
for my bot i need to make keyboard markup but i'm not sure how to do it.
I tried this but it didn't work:
$keyboard = array(
'keyboard' => array(
array("A", "B")
)
);
$client->sendMessage(array('chat_id' => $chatid, 'text' => 'test', 'reply_markup' => $keyboard));
Hi!
When I'm trying send message with inlineKeyboard (using reply_markup
).
...
$buttons[] = [new InlineKeyboardButton([
'text' => $route->name,
'callback_data' => $route->id
])];
...
'reply_markup' => new InlineKeyboardMarkup(['inline_keyboard' => $buttons])
...
I'm getting an error
Code: 400. Description: "Bad Request: can't parse inline keyboard button: Field "url" must be of type String
Coz reply_markup
contains all params including empty url
and switch_inline_query
[reply_markup] => {"inline_keyboard":[[{"text":"Www","url":null,"callback_data":1,"switch_inline_query":null}]]}
Hello.
I want to use my bot with webhook method not with getUpdates.
It works very good with your deamon approach.
Also it works with this component and its method https://github.com/unreal4u/telegram-api/wiki/Getting-updates-via-Webhook
I tried do somethimg like this
use Zelenin\Telegram\Bot\Type\Update;
$update = new Update($_POST);
but it doesn't work.
I got an error:
TypeError: Argument 1 passed to Zelenin\Telegram\Bot\Type\Type::create() must be an instance of stdClass, array given, called in /var/www/telegram/vendor/zelenin/telegram-bot-api/Type/Update.php on line 60 and defined in /var/www/telegram/vendor/zelenin/telegram-bot-api/Type/Type.php:51
Please, update API with tools for group.
I write in php
$response = $api->leaveChat();
but console says
PHP Fatal error: Uncaught Error: Call to undefined method Zelenin\Telegram\Bot\Api::leaveChat()
Can you tell me the correct way to use this function?
hi,
How to obtain chat_id
thanks
my codes for sending audio file is like this
$url = 'http://test/test.mp3';
sendAudio([
'audio' => fopen($url ,'r')
]);
it works great for small files but if url file is larger than 5 Mb I have request timeout error on server logs and it sends that file many time because of looping
I use heroku
after update to version 1.0
$client = new Zelenin\Telegram\Bot\Api($token);
display this error:
PHP Fatal error: Uncaught TypeError: Argument 1 passed to Zelenin\Telegram\Bot\Api::__construct() must be an instance of Zelenin\Telegram\Bot\Client\Client, string given, called in /app/index.php on line 26 and defined in /app/vendor/zelenin/telegram-bot-api/Api.php:26
what should I do?
Does this client support long polling?
when i want to send a document with url or link , i use this code :
$client -> sendDocument(array('chat_id' => $chatid, 'document' => fopen($link, 'r')));
But now i want to know , How i can send file with file_id ? for Ex : BQADBAAD7QIAAoFEJAXq2UtTclEUhQI
i test this code :
$client -> sendDocument(array('chat_id' => $chatid, 'document' => 'BQADBAAD7QIAAoFEJAXq2UtTclEUhQI'));
but's not working !
plz help me !
Thanks
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.