Api.ai从php webhook发送电子邮件

时间:2017-11-29 02:12:51

标签: php heroku webhooks dialogflow

我有一个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";
}

?>

0 个答案:

没有答案