summaryrefslogtreecommitdiffstats
path: root/docs/index.rst
blob: a229b3c5a8765c2889101227853b7b1765de5b9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
.. Services_Twilio documentation master file, created by
   sphinx-quickstart on Tue Mar  8 04:02:01 2011.
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

=================
**twilio-php**
=================

Status
=======

This documentation is for version 4.12.0 of `twilio-php
<https://www.github.com/twilio/twilio-php>`_.

Quickstart
============

Send an SMS
>>>>>>>>>>>

.. code-block:: php

    // Download the library and copy into the folder containing this file.
    require('/path/to/twilio-php/Services/Twilio.php');

    $account_sid = "ACXXXXXX"; // Your Twilio account sid
    $auth_token = "YYYYYY"; // Your Twilio auth token

    $client = new Services_Twilio($account_sid, $auth_token);
    $message = $client->account->messages->sendMessage(
      '+14085551234', // From a Twilio number in your account
      '+12125551234', // Text any number
      "Hello monkey!"
    );

    print $message->sid;

Make a Call
>>>>>>>>>>>>>>

.. code-block:: php

    // Download the library and copy into the folder containing this file.
    require('/path/to/twilio-php/Services/Twilio.php');

    $account_sid = "ACXXXXXX"; // Your Twilio account sid
    $auth_token = "YYYYYY"; // Your Twilio auth token

    $client = new Services_Twilio($account_sid, $auth_token);
    $call = $client->account->calls->create(
      '+14085551234', // From a Twilio number in your account
      '+12125551234', // Call any number

      // Read TwiML at this URL when a call connects (hold music)
      'http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient'
    );

Generating TwiML
>>>>>>>>>>>>>>>>

To control phone calls, your application needs to output `TwiML
<http://www.twilio.com/docs/api/twiml/>`_. Use :class:`Services_Twilio_Twiml`
to easily create such responses.

.. code-block:: php

    $response = new Services_Twilio_Twiml();
    $response->say('Hello');
    $response->play('https://api.twilio.com/cowbell.mp3', array("loop" => 5));
    print $response;

.. code-block:: xml

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

View more examples of TwiML generation here: :ref:`usage-twiml`

Creating a Task
===================

You can easily create a task. Tasks can represent whatever type of work is important for your team. Twilio applications can create tasks from phone calls or SMS messages. 

.. code-block:: php

    require 'Services/Twilio.php';

    $accountSid = 'YOUR_ACCOUNT_SID';
    $authToken = 'YOUR_AUTH_TOKEN';
    $workspaceSid = 'YOUR_WORKSPACE_SID';

    // instantiate a Twilio TaskRouter Client 
    $taskrouterClient = new TaskRouter_Services_Twilio($accountSid, $authToken, $workspaceSid);
    
    // set task parameters
    $workflowSid = 'YOUR_WORKFLOW_SID'; 
    $taskAttributes = '{"selected_language": "fr"}';
    $priority = 10; 
    $timeout = 100;  

    // create task
    $task = $taskrouterClient->workspace->tasks->create(
        $taskAttributes, 
        $workflowSid, 
        array(
            'Priority' => $priority, 
            'Timeout' => $timeout
        )
    ); 
    
    // confirm task created
    echo "Created Task: ".$task->sid; 

Find more examples and details of TaskRouter here: :ref:`usage-taskrouter`

Installation
============

There are two ways to install **twilio-php**: via Composer, or by
downloading the source.

Via Composer
>>>>>>>>>>>>>

.. code-block:: bash

	composer require 'twilio/sdk'

From Source
>>>>>>>>>>>>>

If you aren't using Composer, download the `source (.zip)
<https://github.com/twilio/twilio-php/zipball/master>`_, which includes all the
dependencies.

User Guide
==================

REST API
>>>>>>>>>>

.. toctree::
    :maxdepth: 2
    :glob:

    usage/rest
    usage/rest/*

TwiML and other utilities
>>>>>>>>>>>>>>>>>>>>>>>>>>

.. toctree::
    :maxdepth: 1

    usage/twiml
    usage/validation
    usage/token-generation
    faq/

TaskRouter Reference
>>>>>>>>>>>>>>>>>>>>>

.. toctree::
    :maxdepth: 2
    :glob:

    usage/taskrouter
    usage/taskrouter/*

API Documentation
==================

.. toctree::
    :maxdepth: 3
    :glob:

    api/*


Support and Development
===========================

All development occurs on `Github <https://github.com/twilio/twilio-php>`_. To
check out the source, run

.. code-block:: bash

    git clone git@github.com:twilio/twilio-php.git

Report bugs using the Github `issue tracker <https://github.com/twilio/twilio-php/issues>`_.

If you've got questions that aren't answered by this documentation, ask the
Twilio support team at help@twilio.com.

Running the Tests
>>>>>>>>>>>>>>>>>>>>>>>>>

The unit tests depend on `Mockery <https://github.com/padraic/mockery>`_ and
`PHPUnit <https://github.com/sebastianbergmann/phpunit>`_. First, 'discover' all
the necessary `PEAR` channels:

.. code-block:: bash

    make test-install

After installation, run the tests with :data:`make`.

.. code-block:: bash

    make test


Making the Documentation
>>>>>>>>>>>>>>>>>>>>>>>>>>

Our documentation is written using `Sphinx <http://sphinx.pocoo.org/>`_. You'll
need to install Sphinx and the Sphinx PHP domain before you can build the docs.

.. code-block:: bash

    make docs-install

Once you have those installed, making the docs is easy.

.. code-block:: bash

    make docs