Comments (18)
@shankar96 Not sure why you're asking about node.js in a php project?
But anyway, Telegram tries to resend the message until you respond it with header status code 200, once you do that, their system thinks you accepted the update. Just do that and it'll stop it.
from telegram-bot-sdk.
Can you post your code? Without that it would be hard to tell where the problem could be.
Also do you use it with Laravel or just standalone? Maybe share your log as well.
from telegram-bot-sdk.
Yes this is my code:
$updates = Telegram::getWebhookUpdates();
$response = json_decode(file_get_contents('php://input'));
$chat_id = $response->message->chat->id;
$response = Telegram::sendMessage($chat_id, "Thanks", false, null, null);
Telegram::getMessageId();
return response()->json(["status" => "success"]);
Now if a user send Message to my Bot ,"Thanks" Message always send to the user!!
I don't know why but I'm sure Telegram call my webhook as repetitious
I use it with Laravel 5.1
from telegram-bot-sdk.
Try this, it works for me:
$telegram = new Telegram();
$update = $telegram->getWebhookUpdates();
$message = new Message($update->get('message'));
$telegram->sendMessage($message['chat']['id'], 'Hello, this is a bot');
from telegram-bot-sdk.
Thanks @defunctl
But Can you tell me what is the Message class ?
I don't have it
from telegram-bot-sdk.
It's an object of this package. https://github.com/irazasyed/telegram-bot-sdk/blob/master/src/Objects/Message.php
from telegram-bot-sdk.
@hamo0n It seems like you're using Laravel?
Here's how i would do that:
$update = Telegram::getWebhookUpdates();
$chat_id = $update->getMessage()->getChat()->getId();
Telegram::sendMessage($chat_id, "Thanks", false, null, null);
return response()->json(["status" => "success"]);
@defunctl The library will automatically map all the relations to the appropriate object class, So you don't have to map it again.
So when you make a call to getWebhookUpdates()
method, The response is first mapped to the Update
class, then since the response would content message
key in its object, the library will then map it to the Message class automatically. Hence, You can get chat id by just doing:
$chat_id = $update->getMessage()->getChat()->getId();
from telegram-bot-sdk.
@hamo0n If your script returns any Error and status code other than 200 which it does based on your code, Then Telegram servers assume the update wasn't accepted and failed from your end. So they end up retrying for a few times, due to which you're getting that message multiple times. FYI.
from telegram-bot-sdk.
thanks @irazasyed But the problem still remains :(
new Function after change:
$update = Telegram::getWebhookUpdates();
$chat_id = $update->getMessage()->getChat()->getId();
$command = $this->analyzeText($update->getMessage()->getText());
switch ($command) {
case "start":
$this->startFirstChat($chat_id);
break;
default :
$this->sendMessage($chat_id, "Thanks");
break;
}
return (new Response(["status" => "success"], 200))
->header('Content-Type', "Application/json");
from telegram-bot-sdk.
It seems like you're working on commands area, Why don't you use the built in commands system that i pushed recently?
Check this comment i made here, It's in development, So you need to follow all the instructions there and try.
from telegram-bot-sdk.
BTW, Laravel has CSRF Middleware protection for any POST routes ON by default. You need to make sure you add your route to the except
array inside app/Http/Middleware/VerifyCsrfToken.php
file (Laravel 5 has it). If you don't do that, then it'll always fail because the middleware is checking for a valid token which obviously is not present.
from telegram-bot-sdk.
I commented VerifyCsrfToken because of this.
Edit:
I run api manually and this error was shown to me:
ErrorException in Telegram.php line 653:
Undefined offset: 0
you know last day It was Ok and worked !
from telegram-bot-sdk.
Well, It's a problem from your end as i tested and I'm using this with my bots too. It's working absolutely fine. Now how you've implemented is something i have no idea about. You're giving me parts of the codes and based on that, I've suggested you on how to go about it.
from telegram-bot-sdk.
@irazasyed. This package works fine on my local host.
I thinks the host has a problem.
I'm working on package for solve this problem.
Thank you
from telegram-bot-sdk.
Okay! Let me know if you find a problem with this SDK. Please create a new issue ticket. Thanks!
from telegram-bot-sdk.
hi
im pretty new in creating a telegram bot..
can you give me such an example.. how to set webhook in laravel using this sdk..
and how to get message from my users that using my bot..
thank you
from telegram-bot-sdk.
I have the same problem and have no idea why ?!
exception 'ErrorException' with message 'Undefined offset: 0' in /var/www/shokraneh/vendor/irazasyed/telegram-bot-sdk/src/Api.php:1057
try {
$update = \Telegram::getWebhookUpdate();
\Storage::put('done.txt', $update)
} catch (\Exception $e) {
\Storage::put('error.txt', $e);
return response()->json(["status" => "success"]);
}
Help please
from telegram-bot-sdk.
I have the same problem and have no idea why ?!
exception 'ErrorException' with message 'Undefined offset: 0' in /var/www/shokraneh/vendor/irazasyed/telegram-bot-sdk/src/Api.php:1057
try {
$update = \Telegram::getWebhookUpdate();
\Storage::put('done.txt', $update)
} catch (\Exception $e) {
\Storage::put('error.txt', $e);
return response()->json(["status" => "success"]);
}Help please
Make sure you are using v3.0.0
from telegram-bot-sdk.
Related Issues (20)
- sendMediaGroup can't send video without sound HOT 1
- Sending double message after using setWebhook method HOT 1
- Fatal error: Uncaught Error: Call to undefined function GuzzleHttp\Promise\unwrap() HOT 5
- Forbidden response HOT 1
- Command class "App\Telegram\Commands\StartCommand" should be an instance of "Telegram\Bot\Commands\CommandInterface" HOT 1
- setWebhook() and deleteWebhook() call returns undefined index for result array HOT 1
- Method [replyKeyboardMarkup] does not exist. HOT 3
- Command class "App\Services\Telegram\Commands\StartCommand" should be an instance of "Telegram\Bot\Commands\CommandInterface" HOT 1
- replyWithMessage with multiple bots not working HOT 1
- The Telegram::getWebhookUpdate() result always empty array [] HOT 3
- Get Channel Group Members HOT 6
- Bad Request: file must be non-empty
- Getting message list of a channel HOT 2
- "illuminate/support" 11 support HOT 1
- Wrong response from the webhook: 403 Forbidden HOT 2
- Unit Testing
- Is there a way to receive an event when a new member joins a channel? HOT 1
- Catch exception if user blocked the bot
- Make integration with birthday class
- Keyboard reply command handler not working
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from telegram-bot-sdk.