PHP sdk for mobtexting
You can install mobtexting-php via composer or by downloading the source.
mobtexting-php is available on Packagist as the
mobtexting/voice-sdk
package.
To control phone calls, your application needs to output [JSON] response. Use Mobtexting\Voice
to easily create such responses.
<?php
$response = new Mobtexting\Voice();
$response->answer();
$response->say('Hello');
$response->play('https://domain.com/cowbell.mp3');
print $response;
That will output JSON that looks like this:
[
{
"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
The Answer
tag answers the call. One call answers billing will get started.
You can't nest any other tags inside this Answer
Tag
Attributes
Answer
tag allows following attributes.
delay
no of seconds delay the call before answer.
The Delay
tag will allow you to wait the call before going to next tag.
Attributes
Delay
tag allows the following attributes.
seconds
no of seconds to delay
Some times we have to nest the tags within other tag.
Following tags allow nested tags
- menu
- url
- 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]
}
}
]
$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
}
}
]
}
}
]