我正在尝试在 laravel 中使用 Botman 中的本机按钮和问题功能,但是我很难理解如何在不使用静态函数的情况下链接函数。我让它在一切都是静态功能的地方工作,但是我想使用收集到的所有信息来发送电子邮件。
// initialization function
public function handle()
{
$botman->hears("{message}", function($botman, $message) {
$this->selectHelpQuery($botman);
});
}
// ask question function
public function selectHelpQuery($botman)
{
$question = Question::create("How can i help you, would you like to know about the following:")
->fallback("Unable to help at this time, please try again later")
->callbackId("choose_query")
->addButtons([
Button::create("button1")->value("val1"),
Button::create("button2")->value("val2"),
]);
$botman->ask($question, function (Answer $answer, $botman) {
// Detect if button was clicked:
if ($answer->isInteractiveMessageReply()) {
if($answer->getValue() == "val1")
{
$this->contactFollowUp($botman); //** not working
} else {
$this->contactNoFollowUp($botman); //** not working
}
}
});
}
// other functions.....
但是,没有将contactFollowUp()函数声明为静态并使用类名访问它BotManController::contactFollowUp($botman)但是如果我这样做,我在访问和设置用于其他函数的数据时会遇到问题。具体来说,我得到一个 Method contactFollowUp 不存在错误。