-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
194 lines (150 loc) · 8.43 KB
/
Copy pathProgram.cs
File metadata and controls
194 lines (150 loc) · 8.43 KB
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
using System;
using System.Threading;
namespace TelAPI.Example
{
class Program
{
/// <summary>
/// TelApi account sid. You can get it from TelApi dashboard.
/// </summary>
private const string AccountSid = "your-account-sid";
/// <summary>
/// TelApi auth token. You can get it from TelApi dashboard
/// </summary>
private const string AuthToken = "your-auth-token";
/// <summary>
/// Phone number which will receive our sms and calls from TelApi service
/// </summary>
private const string PhoneNumberTo = "phone-number-to";
/// <summary>
/// Our valid Telapi phone number that we purchased and we will use it for sending SMS and calls
/// </summary>
private const string PhoneNumberFrom = "phone-number-from";
static void Main(string[] args)
{
// First we need to create TelApi Rest client. To do so, we need to provide accountSid, and authToken.
var telApi = new TelAPIRestClient(AccountSid, AuthToken);
// Also there is another way of creating TelApi Rest client with TelAPIConfiguration interface.
// Check DefaultTelAPIConfiguration class for exammple
// var telApi = new TelAPIRestClient(new DefaultTelAPIConfiguration());
// First we will get our Telapi account information
var account = telApi.GetAccount();
Console.WriteLine("Account Sid : {0}", account.Sid);
Console.WriteLine("Account Balance : {0}", account.AccountBalance);
Console.WriteLine("Account Created : {0}", account.DateCreated);
Console.WriteLine("Account Status : {0}", account.Status);
Console.WriteLine();
// Now we will try to send our first SMS message using TelAPI service.
// It's always good to decorate all API calls with the try / catch block
// so that we can catch any exception if something wrong occurs.
try
{
var sms = telApi.SendSmsMessage(PhoneNumberFrom, PhoneNumberTo, "Hello from TelApi.");
Console.WriteLine("SMS Sid : {0}", sms.Sid);
Console.WriteLine("SMS Cost : {0}", sms.Price);
Console.WriteLine("SMS Sent : {0}", sms.DateSent);
Console.WriteLine("SMS Type : {0}", sms.Direction);
}
catch (TelAPIException ex)
{
//If something wrong happens we will catch Telapi exception and print it out
Console.WriteLine("Error message : {0}", ex.Message);
}
Console.WriteLine();
// We can also get all SMS messages that we SENT and RECEIVED from TelApi service.
// We can also filter list with some Sms message options using SmsMessageListOptions() class
// We will ask for all SMS that we sent or received today.
Console.WriteLine("SMS Messages List");
var messageOptions = new SmsMessageListOptions();
messageOptions.DateSent = DateTime.Today;
var messages = telApi.GetSmsMessages(messageOptions);
foreach (var m in messages.SmsMessages)
{
Console.WriteLine("From : {0} To : {1} Body : {2}", m.From, m.To, m.Body);
}
Console.WriteLine();
// Also we can make calls with just one method call.
// We need to provide number from which we will make call (our Telapi purchased number)
// and number which we will call. Also valid URL is needed where Telapi will send some call data
var call = telApi.MakeCall(PhoneNumberFrom, PhoneNumberTo, "http://www.some-url-for-telapi-data.com");
Console.WriteLine("Call Sid : {0}", call.Sid);
Console.WriteLine("Call Status : {0}", call.Status.ToString());
Console.WriteLine("Call Created : {0}", call.DateCreated);
Console.WriteLine();
// We can do various task on calls like sending digits, voice effects, interrupt or hangup call
// We can also RECORD call which we will do in the next lines. We will wait some time, before turning recording ON
// Then after another SLEEP we will turn OFF recording
Thread.Sleep(5000);
try
{
var startRecord = telApi.RecordCall(call.Sid, true);
}
catch (TelAPIException ex)
{
//If something wrong happens we will catch Telapi exception and print it out
Console.WriteLine("Error message : {0}", ex.Message);
}
Console.WriteLine();
Thread.Sleep(5000);
try
{
var stopRecord = telApi.RecordCall(call.Sid, false);
}
catch (TelAPIException ex)
{
//If something wrong happens we will catch Telapi exception and print it out
Console.WriteLine("Error message : {0}", ex.Message);
}
Console.WriteLine();
// Now we will hangup our call using HangupCall(). Also you can hangup call using
// InterruptCall() method and specify the reason of interruption
var hangupCall = telApi.HangupCall(call.Sid);
Console.WriteLine("Hangup Call Sid : {0}", hangupCall.Sid);
Console.WriteLine("Hangup Call Duration : {0}", hangupCall.Duration);
Console.WriteLine("Hangup Call Status : {0}", hangupCall.Status.ToString());
Console.WriteLine();
// We also can query TelApi service for avaliable phone number which we want to purchase.
// We can also filter that list with various parameters
// For example we will query for all avaliable US numbers
var numbers = telApi.GetAvailablePhoneNumbers("US");
foreach (var a in numbers.AvailablePhoneNumbers)
{
Console.WriteLine("Avaliable Phone Number : {0}", a.PhoneNumber);
}
Console.WriteLine();
// There is also options to query our own TelApi numbers that we purchased
var incomingNumbers = telApi.GetIncomingPhoneNumbers();
foreach (var i in incomingNumbers.IncomingPhoneNumbers)
{
Console.WriteLine("Incoming Phone Number : {0}", i.PhoneNumber);
}
Console.WriteLine();
// Telapi service provide us with Transcribing feauture. That means
// that we can provide some external audio Url which Telapi will transcribe for us
// and save result on our account which then we can get using TelApi api
var transcribe = telApi.TranscribeAudio("http://www.some-external-audio-url.com");
Console.WriteLine("Transcribe Sid : {0}", transcribe.Sid);
Console.WriteLine("Transcribe Started : {0}", transcribe.DateCreated);
Console.WriteLine("Transcribe Status : {0}", transcribe.Status.ToString());
Console.WriteLine();
// If we want to find some information about Phone or Landline numbers
// we can use Carrier and CNAM lookup using TelApi service
var resultCarrier = telApi.CarrierLookup(PhoneNumberFrom);
foreach (var carrier in resultCarrier.CarrierLookups)
{
Console.WriteLine("Carrier Name : {0}", carrier.Carrier);
Console.WriteLine("Carrier Country : {0}", carrier.Country);
Console.WriteLine("Carrier Lookup Price : {0}", carrier.Price);
}
Console.WriteLine();
var resultCnam = telApi.CNAMLookup(PhoneNumberFrom);
foreach (var cnam in resultCnam.CNAMDips)
{
Console.WriteLine("CNAM Body : {0}", cnam.Body);
}
// The End :)
Console.WriteLine("The end :)");
Console.ReadKey();
}
}
}