gambry / dialogflow-webhook
DialogFlow Webhook Fulfillment PHP SDK
2.2.0
2023-02-27 14:35 UTC
Requires
- php: >=7.3
Requires (Dev)
- phpunit/phpunit: ^9.6
This package is auto-updated.
Last update: 2024-09-27 17:59:16 UTC
README
这是一个为Dialogflow Fulfillment提供的非官方php SDK。
如果你在寻找检测意图和代理API的php SDK,请查看官方仓库.
Dialogflow: Build brand-unique, natural language interactions for bots, applications and devices.
安装
通过composer
$ composer require gambry/dialogflow-webhook
使用方法
在你的webhook请求处理器中
require_once __DIR__.'/vendor/autoload.php'; if ($webhook_json = json_decode($request_body, TRUE)) { $request = new \DialogFlow\Model\Webhook\Request($webhook_json); $intent_name = $request->getResult()->getIntent()->getIntentName(); if ($intent_name === 'HelloWorld') { $fulfillment = new \DialogFlow\Model\Fulfillment(); $fulfillment->setText('Hi from the fulfilment!'); $response = new \DialogFlow\Model\Webhook\Response(); $response->setFulfillment($fulfillment); echo json_encode($response); } }
注意:根据你处理请求的方式、库的自动加载方式以及返回response的方式可能有所不同。