【发布时间】:2017-11-29 02:12:50
【问题描述】:
我有一个 php webhook,我在 Heroku 上托管它,evertyhing 工作正常。当我在 api.ai 上对其进行测试时,机器人会以我想要的方式回答我,所以它可以正常工作。我的问题是:如何从我的 webhook 发送电子邮件或在数据库中插入文本? 这是我的代码:
<?php
$method = $_SERVER['REQUEST_METHOD'];
//$msg = "First line of text\nSecond line of text";
// use wordwrap() if lines are longer than 70 characters
//$msg = wordwrap($msg,70);
// send email
//mail("moscosisi@gmail.com","My subject",$msg);
// Process only when method is POST
if($method == 'POST'){
$requestBody = file_get_contents('php://input');
$json = json_decode($requestBody);
$equis = $json->result->parameters->equis;
switch ($equis) {
case 'hi':
$speech = "Hi, Nice to meet you";
break;
case 'bye':
$speech = "Bye, good night";
break;
case 'anything':
$speech = "Yes, you can type anything here.";
break;
default:
$speech = "Sorry, I didnt get that. Please ask me something
else.";
break;
}
$response = new \stdClass();
$response->speech = $speech;
$response->displayText = $speech;
$response->source = "Alex";
echo json_encode($response);
}
else
{
echo "Method not allowed";
}
?>
【问题讨论】:
-
电子邮件是通过回调作为参数发送给您的,这是一个我如何在 PHP 中发送电子邮件 的问题,或者它是一个 我如何匹配上下文操作中的电子邮件?
-
btw 实现适用于您收集数据或需要查询其他数据时,而不是基本的机器人响应,它们应该有意图地完成。
-
我想通过电子邮件发送 $spech 但我不知道该怎么做
标签: php heroku webhooks dialogflow-es