I created custom command by following steps as mentioned in url
https://github.com/php-telegram-bot/core/wiki/Create-your-own-commands
and executed that but commend not executed, even predefined commands also executed but it also not working. Please help me out.
maybe posting your code would help us out helping you out
+1. Not working lib on webHooks. ON commands zero reaction.
Controller (hook is set, url is corrent)
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Longman\TelegramBot\Telegram;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\TelegramLog;
class TelegramController extends Controller
{
protected $token = 'myToken';
protected $username = 'myUsername';
protected $hookUrl = 'https://4d1155ab.ngrok.io/telegram-api/onmessage';
protected $commandsPaths = [
"D:\\Web\\telegram.local\\app\\TelegramCommands\\",
];
protected $bot;
// Create Telegram API object
public function __construct()
{
parent::__construct();
$this->bot = new Telegram($this->token, $this->username);
TelegramLog::initErrorLog($this->commandsPaths[0] . "/{$this->username}_error.log");
TelegramLog::initDebugLog($this->commandsPaths[0] . "/{$this->username}_debug.log");
TelegramLog::initUpdateLog($this->commandsPaths[0] . "/{$this->username}_update.log");
//#2- Enable requests limiter, to prevent attack like requests
//This prevents library from processing repetitive requests
$this->bot->enableLimiter();
//#3- A database for the library
$mysql_credentials = [
'host' => env('DB_HOST'),
'user' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'database' => env('DB_DATABASE'),
];
$this->bot->enableMySql($mysql_credentials);
}
public function setWebhook() {
try {
// Set webhook
$result = $this->bot->setWebhook($this->hookUrl);
if ($result->isOk()) {
dd($result->getDescription());
}
} catch (TelegramException $e) {
dd('Error telegram: ' . $e->getMessage());
}
}
public function removeWebhook() {
try {
$this->bot->deleteWebhook();
} catch (TelegramException $e) {
dd('Error telegram: ' . $e->getMessage());
}
}
public function onMessage() {
try {
$this->bot->addCommandsPaths($this->commandsPaths);
$this->bot->handle();
} catch (TelegramException $e) {
dd('Error telegram: ' . $e->getMessage());
}
}
}
Command
<?php
namespace Longman\TelegramBot\Commands\UserCommands;
use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Request;
use Illuminate\Support\Facades\Log;
class TestCommand extends UserCommand
{
protected $name = 'test'; // Your command's name
protected $description = 'A command for test'; // Your command description
protected $usage = '/test'; // Usage of your command
protected $version = '1.0.0'; // Version of your command
public function execute()
{
$message = $this->getMessage(); // Get Message object
$chat_id = $message->getChat()->getId(); // Get the current Chat ID
$data = [ // Set up the new message data
'chat_id' => $chat_id, // Set Chat ID to send the message to
'text' => 'This is just a Test...', // Set message to send
];
return Request::sendMessage($data); // Send message!
}
}
Logs contans only success messages about set webhook. And nothing after send message to bot...
I see you're on Windows, which needs a custom Guzzle client with disabled verification.
Look at #381 and #536.
Thx, but solution for me is disable CSRF token for API in Laravel moving route to another middleware (from 'web' to 'api').
Ok! So the commands are working for you then? Also without the Windows Guzzle fix?
@sachin-lalaworld What about you?
My issue has been resolved.
Regards
Sachin Sharma
Software Developer
On Nov 8, 2017 5:59 PM, "Armando Lüscher" notifications@github.com wrote:
Ok! So the commands are working for you then? Also without the Windows
Guzzle fix?@sachin-lalaworld https://github.com/sachin-lalaworld What about you?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/php-telegram-bot/core/issues/684#issuecomment-342803606,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AetA_GN5y0SBTCyiIUQt6oCLh_hFPZjNks5s0Z7FgaJpZM4QFg_A
.
Most helpful comment
maybe posting your code would help us out helping you out