Skip to content

Latest commit

 

History

History
100 lines (74 loc) · 2.27 KB

README.md

File metadata and controls

100 lines (74 loc) · 2.27 KB

tiniyo-php

tiniyo-php provides sdk for tiniyo apis.

Supported PHP Versions

This library supports the following PHP implementations:

  • PHP 7.2
  • PHP 7.3
  • PHP 7.4
  • PHP 8.0.1

Installation

You can install tiniyo-php via composer or by downloading the source.

Via Composer:

tiniyo-php is available on Packagist as the tiniyo/tiniyo-php package:

composer require tiniyo/tiniyo-php

Quickstart

Send an SMS

// Send an SMS using tiniyo's REST API and PHP
<?php
$sid = "ACXXXXXX"; // Your Account SID from https://tiniyo.com
$token = "YYYYYY"; // Your Auth Token from https://tiniyo.com

$client = new Tiniyo\Rest\Client($sid, $token);
$message = $client->messages->create(
  '8881231234', // Text this number
  [
    'from' => '9991231234', // From a valid Tiniyo number or approved senderid
    'body' => 'Hello from Tiniyo!'
  ]
);

print $message->sid;

Make a Call

<?php
$sid = "ACXXXXXX"; // Your Account SID from https://tiniyo.com
$token = "YYYYYY"; // Your Auth Token from https://tiniyo.com

$client = new Tiniyo\Rest\Client($sid, $token);

// Read tinixml at this URL when a call connects (hold music)
$call = $client->calls->create(
  '8881231234', // Call this number
  '9991231234', // From a valid Tiniyo number
  [
      'url' => 'https://raw.githubusercontent.com/tiniyo/public/master/answer_speak.xml'
  ]
);

Enable Debug Logging

You can set the log level to debug to enable debug logging in the default HTTP client

$sid = "ACXXXXXX"; // Your Account SID from https://tiniyo.com
$token = "YYYYYY"; // Your Auth Token from https://tiniyo.com

$client = new Tiniyo\Rest\Client($sid, $token);
$client->setLogLevel('debug');

Generating Tinixml

To control phone calls, your application needs to output Tinixml.

Use Tiniyo\Tinixml\(Voice|Messaging|Fax)Response to easily chain said responses.

<?php
$response = new Tiniyo\Tinixml\VoiceResponse();
$response->say('Hello');
$response->play('https://api.tiniyo.com/cowbell.mp3', ['loop' => 5]);
print $response;

That will output XML that looks like this:

<?xml version="1.0" encoding="utf-8"?>
<Response>
    <Say>Hello</Say>
    <Play loop="5">https://api.tiniyo.com/cowbell.mp3</Play>
</Response>