-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTwilioMessaging
38 lines (34 loc) · 982 Bytes
/
TwilioMessaging
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
using UnityEngine;
using System.Collections;
public class TwilioMessaging : MonoBehaviour
{
string url = "api.twilio.com/2010-04-01/Accounts/";
string service="/Messages.json";
public string from;
public string to;
public string account_sid;
public string auth;
public string body;
public void SendSMS ()
{
WWWForm form = new WWWForm ();
form.AddField ("To", to);
form.AddField ("From", from);
//string bodyWithoutSpace = body.Replace (" ", "%20");//Twilio doesn't need this conversion
form.AddField ("Body", body);
string completeurl = "https://"+account_sid+":" + auth +"@" +url+account_sid+service;
Debug.Log (completeurl);
WWW www = new WWW (completeurl, form);
StartCoroutine (WaitForRequest (www));
}
IEnumerator WaitForRequest (WWW www)
{
yield return www;
// check for errors
if (www.error == null) {
Debug.Log ("WWW Ok! SMS sent through Web API: " + www.text);
} else {
Debug.Log ("WWW Error: " + www.error);
}
}
}