事件onConversation被触发,但用户什么也得不到。我试图修复错误,但消息尚未发送。所有其他僵尸程序的功能都运行正常。
请告诉我错误在哪里,以及我如何修复它。
$bot = new Bot(['token' => $apiKey]);
$bot
->onConversation(function ($event) use ($bot, $botSender, $log ) {
$log->info('onConversation ' . var_export($event, true));
$context = $event->getContext();
if ($context != "" && $context != null) {
add_with_referral($event->getSender()->getId(), $event->getSender()->getName(), $context);
} else {
add_user($event->getSender()->getId(), $event->getSender()->getName(), $log);
}
return (new \Viber\Api\Message\Text)
->setSender($botSender)
->setText("Can i help you?");
})我使用SDK Bogdaan/viber-bot
发布于 2021-08-18 21:14:49
Нашелрешение。onConversation>Удаляемстандартноесобытие()。bot.phpВсамоеначалофайлапишемвотэтоткод:
file_put_contents("viber.json",file_get_contents("php://input"));
$viber = file_get_contents("viber.json");
$viber = JSON_decode($viber);
function send($message){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://chatapi.viber.com/pa/send_message",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2_0,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => JSON_encode($message),
CURLOPT_HTTPHEADER => array(
"Cache-Control: no-cache",
"Content-Type: application/JSON",
"X-Viber-Auth-Token: YOUR VIBER TOKEN"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
}
$main_menu = [[
"Columns"=> 6,
"Rows"=> 2,
"BgColor" => "#808B96",
"ActionType" => "reply",
"ActionBody" => "subscribe_button",
"Text" => "<font color=\"#F8F9F9\"><b>Subscribe</b></font>",
"TextSize" => "regular"
]];
if ($viber->event == "conversation_started"){
$message['receiver'] = $viber->user->id;
$message['type'] = "text";
$message['text'] = "text";
$message['keyboard'] = [
"Type" => "keyboard",
"Revision" => 1,
"DefaultHeight" => false,
"Buttons" => $main_menu
];
send($message);
exit;
}https://stackoverflow.com/questions/68825196
复制相似问题