mobtexting / voice-sdk
此包已被弃用且不再维护。未建议替代包。
Mobtexting语音服务PHP SDK
v0.1.3
2018-10-30 10:48 UTC
Requires
- php: >= 5.5
This package is auto-updated.
Last update: 2020-12-22 08:54:39 UTC
README
mobtexting的PHP SDK
安装
您可以通过composer安装 mobtexting-php 或下载源代码。
通过Composer
mobtexting-php 作为 mobtexting/voice-sdk 包在Packagist上提供。
快速入门
生成JSON
为了控制电话呼叫,您的应用程序需要输出[JSON]响应。使用 Mobtexting\Voice 可以轻松创建此类响应。
<?php $response = new Mobtexting\Voice(); $response->answer(); $response->say('Hello'); $response->play('https://domain.com/cowbell.mp3'); print $response;
这将输出如下所示的JSON
[
{
"Answer": {
"delay": 0
}
},
{
"SayText": {
"language": "EN",
"engine": "polly",
"message": "Hello"
}
},
{
"Play": {
"type": "mp3",
"path": "https://domain.com/cowbell.mp3"
}
}
]
命令
- answer - delay - conference - email - filter - hangup - play - record - repeat - say - sayDateTime - sayNumber - sayPin - url
Answer(响应)
Answer 标签会接听电话。一个电话接听账单将开始。您不能在 Answer 标签内嵌套其他任何标签
属性
Answer 标签允许以下属性。
delay在接听电话之前延迟的秒数。
延迟
Delay 标签允许您在进入下一个标签之前等待电话。
属性
Delay 标签允许以下属性。
seconds延迟的秒数
Say 标签
嵌套标签
有时我们必须在其他标签内嵌套标签。
以下标签允许嵌套标签
- menu
- url
- filter
具有嵌套标签的filter标签示例
$response = new Mobtexting\Voice(); $response->answer(); $response->say('Hello'); $filter = $response->filter([10]); $filter->onFail('hangup'); $url = $filter->onPass('Url')->setUrl('google.com'); $url->onResponse('*', 'hangup'); $url->onResponse('x', 'hangup'); echo $response;
响应
[
{
"Answer": {
"delay": 0
}
},
{
"SayText": {
"language": "EN",
"engine": "polly",
"message": "Hello"
}
},
{
"Filter": {
"onpass": {
"Url": {
"method": "get",
"url": "google.com",
"response": {
"*": {
"Hangup": {
"reason": 16
}
},
"x": {
"Hangup": {
"reason": 16
}
}
}
}
},
"onfail": {
"Hangup": {
"reason": 16
}
},
"type": "frequency",
"unit": [10]
}
}
]
具有嵌套标签的filter标签示例
$response = new Mobtexting\Voice(); $response->answer(); $response->say('Hello'); $dial = $response->dial('700xxx', '80300xxxxx'); $dial->setAttribute('retries', 1); $play = $dial->onAnswer('play', ['custom/14d81c2e3c3f8110a7e8f36331e1b9b3']); $play->setAttribute('duration', 30); $play = $dial->onNoAnswer('play', ['custom/14d81c2e3c3f8110a7e8f36331e1b9b3']); echo $response;
响应
[
{
"Answer": {
"delay": 0
}
},
{
"SayText": {
"language": "EN",
"engine": "polly",
"message": "Hello"
}
},
{
"Dial": {
"to": "7008409026",
"callerid": "+918030072306",
"retries": 0,
"onanswer": [
{
"Play": {
"path": "custom/14d81c2e3c3f8110a7e8f36331e1b9b3",
"type": "gsm",
"duration": 30
}
}
],
"onnoanswer": [
{
"Play": {
"path": "custom/d2a3030926b57807e0067244f040f70e",
"type": "gsm",
"duration": 30
}
}
]
}
}
]