Hi,
i want create telegram bot with longman/telegram-bot but my set webhook not work correctly.
when i use irazasyed/telegram-bot-sdk my webhook worked but when use longman webhook not work.
steps:
1- add composer require longman/telegram-bot
2- create module with name telegram
3- create controller with name telegram
my controller code is:
namespace app\modules\telegram\controllers;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Exception\TelegramLogException;
use Longman\TelegramBot\Telegram;
use Longman\TelegramBot\TelegramLog;
use yiif\web\Controller;
class TelegramController extends Controller
{
const API_KEY='324853508:AAFwzEQOq8k08r-5eOdsuXvUe3Lp72D1n-E';
const BOT_NAME='khadem_hw2_bot';
const CERTIFICATE_PATH='/var/sentora/hostdata/tokhone/public_html/tokhone_ir/ssl/ssl.pem';
public function actionSet()
{
$hook_url = 'https domain/telegram/telegram/hook';
try {
// Create Telegram API object
$telegram = new Telegram(self::API_KEY, self::BOT_NAME);
// Set webhook
$result = $telegram->setWebHook($hook_url,self::CERTIFICATE_PATH);
// Uncomment to use certificate
//$result = $telegram->setWebHook($hook_url, $path_certificate);
if ($result->isOk()) {
echo $result->getDescription();
}else{
}
} catch (TelegramException $e) {
echo $e;
}
}
public function actionHook(){
file_put_contents(__DIR__."/dump.html","hook called\n",FILE_APPEND);
try {
// Create Telegram API object
$telegram = new Telegram(self::API_KEY, self::BOT_NAME);
$telegram->addCommandsPath(dirname(__DIR__).'/commands/');
// Handle telegram webhook request
$telegram->handle();
} catch (TelegramException $e) {
// Silence is gold!
echo $e;
// log telegram errors
TelegramLog::error($e);
} catch (TelegramLogException $e) {
// Silence is gold! Uncomment this to catch log initilization errors
echo $e;
}
}
public function actionUnset(){
try {
// Create Telegram API object
$telegram = new Telegram(self::API_KEY, self::BOT_NAME);
// Unset webhook
$result = $telegram->unsetWebHook();
if ($result->isOk()) {
echo $result->getDescription();
}
} catch (TelegramException $e) {
echo $e;
}
}
}
when i create three files set.php, unset.php, hook.php and use irazasyed for init telegram bot akalongman hook worked,
but when use set.php with akalongman my hook not work.
if u can, help me.
thanks