我使用了Laravel 5.0和Irazasyed电报机器人,我想通过webhook工作,当一个人向电报机器人发送消息时,电报会自动向该消息发送消息。
我的代码在这里是webhook无法使用的机器人:
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Technical;
use Illuminate\Support\Facades\Session;
use Url;
use Telegram\Bot\Api;
use Telegram\Bot\Laravel\Facades\Telegram;
use Artisaninweb\SoapWrapper\Facades\SoapWrapper;
class HomeController extends Controller {
public function __construct()
{
//$this->middleware('auth');
}
public function index()
{
$telegram = new Api('117451573:*********************', 'true');
$telegram->setWebhook(['url' => 'https://******.com/117451573:********************/webhook']);
$update = $telegram->getWebhookUpdates();
$telegram->sendMessage([
'chat_id' => '********',
'text' => 'thanks',
]);
return response()->json(["status" => "success"]);
}
}
答案 0 :(得分:2)
我想让Irazasyed's Telegram Bot SDK也能正常工作。下面是一个教程:Let's make a Telegram bot with PHP,这似乎是最新的。我没有时间自己测试一下。接下来的几天会有希望。
要使用webhooks,似乎你必须在shell中调用以下命令一次。
curl -H "Content-Type: application/json" -X POST -d '{"url":"https://www.example.com/my-secret-webhook.php"}' https://api.telegram.org/botYOUR_BOT_TOKEN/setWebhook
见 II章。在教程中配置Webhook 。
祝你好运