├── LICENSE
├── README.md
├── TwilioLib.pas
├── opm
├── TwilioSMS.json
└── TwilioSMS.zip
├── testsms.pas
├── testsms2.pas
├── twilio.lpk
└── twilio.pas
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TwilioLib
2 | A Freepascal library for sending SMS with Twilio
3 |
4 | ## Use
5 | Add TwilioLib to your uses clause
6 |
7 | Instantiate a TTwilio variable, send sms :)
8 |
9 | ### Example
10 |
11 | ```
12 | program testsms.pas;
13 | {$mode objfpc}
14 | uses
15 | Sysutils, Classes, TwilioLib;
16 |
17 | procedure SendSMS;
18 | var
19 | twilio: TTwilio;
20 | twilio_result: TStrings;
21 | begin
22 | twilio_result := TStringList.Create;
23 | try
24 | twilio := TTwilio.create('your sid', 'your secret');
25 | try
26 | try
27 | twilio.send_sms('+OutPhone', '+ToPhone', 'message', twilio_result);
28 | except
29 | on E:ETWilioException do
30 | writeln(e.message)
31 | else raise;
32 | end;
33 | finally
34 | Twilio.Free;
35 | end;
36 | finally
37 | twilio_result.free;
38 | end;
39 | end;
40 |
41 | begin
42 | SendSMS;
43 | end.
44 | ```
45 |
46 | ## Requirements
47 | You need to have a Twilio account, and your account SID.
48 |
49 | ## Future
50 | Right now it only supports sending single SMS, in the future I'll be implementing more functionality that Twilio offers.
51 |
--------------------------------------------------------------------------------
/TwilioLib.pas:
--------------------------------------------------------------------------------
1 | {======================================================
2 | Author Marcus Fernström
3 | Contributor Thaddy de Koning
4 | License LGPL3
5 | Version 0.4
6 | GitHub https://github.com/MFernstrom/TwilioLib
7 | =======================================================}
8 | unit TwilioLib;
9 |
10 | {$mode objfpc}{$H+}{$notes off}
11 |
12 | interface
13 |
14 | uses
15 | Classes, SysUtils, fphttpclient, fpjson, jsonparser, opensslsockets;
16 |
17 | type
18 | ITwilio = interface
19 | ['{7C5DF745-E72C-4652-9FB1-94992F181207}']
20 | procedure send_sms(const from_number, to_number, message: String;var Output: TStrings);
21 | end;
22 |
23 | { TTwilio }
24 |
25 | TTwilio = class(TInterfacedObject, ITwilio)
26 | private
27 | account_sid, auth_token, url : String;
28 | public
29 | constructor create(const sid, token : String);
30 | destructor destroy;override;
31 | procedure send_sms(const from_number, to_number, message: String;var Output: TStrings);
32 | end;
33 |
34 | ETWilioException = Class(Exception);
35 |
36 | implementation
37 |
38 | constructor TTwilio.create(const sid, token: String );
39 | begin
40 | Inherited create;
41 | account_sid := sid;
42 | auth_token := token;
43 | url := 'https://api.twilio.com/2010-04-01/Accounts/' + sid + '/Messages.json';
44 | end;
45 |
46 | destructor TTwilio.Destroy;
47 | begin
48 | inherited Destroy;
49 | end;
50 |
51 | procedure TTwilio.send_sms(const from_number, to_number, message: String;
52 | var Output: TStrings);
53 | var
54 | postVars: TStringlist;
55 | responseData: TStringStream;
56 | pos: Integer = 0;
57 | jObject : TJSONObject = nil;
58 | begin
59 | // Check if the output variable has been initialized
60 | if Assigned(Output) then
61 | begin
62 | Output.Clear;
63 | postVars := TStringlist.Create;
64 | responseData := TStringStream.Create('');
65 | try
66 | // Prep resultVar
67 | Output.CommaText := 'sid=,date_created=,date_updated=,date_sent=,account_sid=,to=,from=,body=,status=,num_segments=,num_media=,direction=,api_version=,price=,price_unit=,error_code=,error_message=,uri=,raw=';
68 |
69 | // postVars holds the API data needed, to/from/body
70 | postVars.Add('To=' + to_number);
71 | postVars.Add('From=' + from_number);
72 | postVars.Add('Body=' + message);
73 |
74 | // Make the api call
75 | With TFPHttpClient.Create(Nil) do
76 | try
77 | UserName := account_sid;
78 | Password := auth_token;
79 | FormPost(url, postVars, responseData);
80 | finally
81 | Free;
82 | end;
83 |
84 | jObject := GetJSON( responseData.DataString ) as TJSONObject;
85 |
86 | for pos := 0 to Output.Count-1 do
87 | if jObject.Get(Output.Names[pos]) <> Null then
88 | Output.Values[Output.Names[pos]] := jObject.Get(Output.Names[pos]);
89 | Output.Values['raw'] := responseData.DataString;
90 | finally
91 | responseData.Free;
92 | jObject.Free;
93 | postVars.Free;
94 | end
95 | end else
96 | raise ETWilioException.Create('No output assigned') at
97 | get_caller_addr(get_frame),
98 | get_caller_frame(get_frame);;
99 | end;
100 | end.
101 |
--------------------------------------------------------------------------------
/opm/TwilioSMS.json:
--------------------------------------------------------------------------------
1 | {
2 | "PackageData0" : {
3 | "Name" : "TwilioLib",
4 | "DisplayName" : "Twilio SMS",
5 | "Category" : "Networking",
6 | "CommunityDescription" : "Easy-to-use library for sending SMS/Text messages through Twilio.com",
7 | "RepositoryFileName" : "TwilioSMS.zip",
8 | "RepositoryFileSize" : 6360,
9 | "RepositoryFileHash" : "81f6cfa4159e9845e81de90e315ec793",
10 | "RepositoryDate" : 4.4066789819212965E+004,
11 | "PackageBaseDir" : "TwilioLib\\/",
12 | "HomePageURL" : "https://github.com/MFernstrom/TwilioLib",
13 | "DownloadURL" : "",
14 | "SVNURL" : ""
15 | },
16 | "PackageFiles0" : [
17 | {
18 | "Name" : "twilio.lpk",
19 | "Description" : "Library for interacting with the Twilio service",
20 | "Author" : "Marcus Fernström",
21 | "License" : " GNU LESSER GENERAL PUBLIC LICENSE\r\n Version 3, 29 June 2007\r\n\r\n Copyright (C) 2007 Free Software Foundation, Inc. \r\n Everyone is permitted to copy and distribute verbatim copies\r\n of this license document, but changing it is not allowed.\r\n\r\n\r\n This version of the GNU Lesser General Public License incorporates\r\nthe terms and conditions of version 3 of the GNU General Public\r\nLicense, supplemented by the additional permissions listed below.\r\n\r\n 0. Additional Definitions.\r\n\r\n As used herein, \"this License\" refers to version 3 of the GNU Lesser\r\nGeneral Public License, and the \"GNU GPL\" refers to version 3 of the GNU\r\nGeneral Public License.\r\n\r\n \"The Library\" refers to a covered work governed by this License,\r\nother than an Application or a Combined Work as defined below.\r\n\r\n An \"Application\" is any work that makes use of an interface provided\r\nby the Library, but which is not otherwise based on the Library.\r\nDefining a subclass of a class defined by the Library is deemed a mode\r\nof using an interface provided by the Library.\r\n\r\n A \"Combined Work\" is a work produced by combining or linking an\r\nApplication with the Library. The particular version of the Library\r\nwith which the Combined Work was made is also called the \"Linked\r\nVersion\".\r\n\r\n The \"Minimal Corresponding Source\" for a Combined Work means the\r\nCorresponding Source for the Combined Work, excluding any source code\r\nfor portions of the Combined Work that, considered in isolation, are\r\nbased on the Application, and not on the Linked Version.\r\n\r\n The \"Corresponding Application Code\" for a Combined Work means the\r\nobject code and/or source code for the Application, including any data\r\nand utility programs needed for reproducing the Combined Work from the\r\nApplication, but excluding the System Libraries of the Combined Work.\r\n\r\n 1. Exception to Section 3 of the GNU GPL.\r\n\r\n You may convey a covered work under sections 3 and 4 of this License\r\nwithout being bound by section 3 of the GNU GPL.\r\n\r\n 2. Conveying Modified Versions.\r\n\r\n If you modify a copy of the Library, and, in your modifications, a\r\nfacility refers to a function or data to be supplied by an Application\r\nthat uses the facility (other than as an argument passed when the\r\nfacility is invoked), then you may convey a copy of the modified\r\nversion:\r\n\r\n a) under this License, provided that you make a good faith effort to\r\n ensure that, in the event an Application does not supply the\r\n function or data, the facility still operates, and performs\r\n whatever part of its purpose remains meaningful, or\r\n\r\n b) under the GNU GPL, with none of the additional permissions of\r\n this License applicable to that copy.\r\n\r\n 3. Object Code Incorporating Material from Library Header Files.\r\n\r\n The object code form of an Application may incorporate material from\r\na header file that is part of the Library. You may convey such object\r\ncode under terms of your choice, provided that, if the incorporated\r\nmaterial is not limited to numerical parameters, data structure\r\nlayouts and accessors, or small macros, inline functions and templates\r\n(ten or fewer lines in length), you do both of the following:\r\n\r\n a) Give prominent notice with each copy of the object code that the\r\n Library is used in it and that the Library and its use are\r\n covered by this License.\r\n\r\n b) Accompany the object code with a copy of the GNU GPL and this license\r\n document.\r\n\r\n 4. Combined Works.\r\n\r\n You may convey a Combined Work under terms of your choice that,\r\ntaken together, effectively do not restrict modification of the\r\nportions of the Library contained in the Combined Work and reverse\r\nengineering for debugging such modifications, if you also do each of\r\nthe following:\r\n\r\n a) Give prominent notice with each copy of the Combined Work that\r\n the Library is used in it and that the Library and its use are\r\n covered by this License.\r\n\r\n b) Accompany the Combined Work with a copy of the GNU GPL and this license\r\n document.\r\n\r\n c) For a Combined Work that displays copyright notices during\r\n execution, include the copyright notice for the Library among\r\n these notices, as well as a reference directing the user to the\r\n copies of the GNU GPL and this license document.\r\n\r\n d) Do one of the following:\r\n\r\n 0) Convey the Minimal Corresponding Source under the terms of this\r\n License, and the Corresponding Application Code in a form\r\n suitable for, and under terms that permit, the user to\r\n recombine or relink the Application with a modified version of\r\n the Linked Version to produce a modified Combined Work, in the\r\n manner specified by section 6 of the GNU GPL for conveying\r\n Corresponding Source.\r\n\r\n 1) Use a suitable shared library mechanism for linking with the\r\n Library. A suitable mechanism is one that (a) uses at run time\r\n a copy of the Library already present on the user's computer\r\n system, and (b) will operate properly with a modified version\r\n of the Library that is interface-compatible with the Linked\r\n Version.\r\n\r\n e) Provide Installation Information, but only if you would otherwise\r\n be required to provide such information under section 6 of the\r\n GNU GPL, and only to the extent that such information is\r\n necessary to install and execute a modified version of the\r\n Combined Work produced by recombining or relinking the\r\n Application with a modified version of the Linked Version. (If\r\n you use option 4d0, the Installation Information must accompany\r\n the Minimal Corresponding Source and Corresponding Application\r\n Code. If you use option 4d1, you must provide the Installation\r\n Information in the manner specified by section 6 of the GNU GPL\r\n for conveying Corresponding Source.)\r\n\r\n 5. Combined Libraries.\r\n\r\n You may place library facilities that are a work based on the\r\nLibrary side by side in a single library together with other library\r\nfacilities that are not Applications and are not covered by this\r\nLicense, and convey such a combined library under terms of your\r\nchoice, if you do both of the following:\r\n\r\n a) Accompany the combined library with a copy of the same work based\r\n on the Library, uncombined with any other library facilities,\r\n conveyed under the terms of this License.\r\n\r\n b) Give prominent notice with the combined library that part of it\r\n is a work based on the Library, and explaining where to find the\r\n accompanying uncombined form of the same work.\r\n\r\n 6. Revised Versions of the GNU Lesser General Public License.\r\n\r\n The Free Software Foundation may publish revised and/or new versions\r\nof the GNU Lesser General Public License from time to time. Such new\r\nversions will be similar in spirit to the present version, but may\r\ndiffer in detail to address new problems or concerns.\r\n\r\n Each version is given a distinguishing version number. If the\r\nLibrary as you received it specifies that a certain numbered version\r\nof the GNU Lesser General Public License \"or any later version\"\r\napplies to it, you have the option of following the terms and\r\nconditions either of that published version or of any later version\r\npublished by the Free Software Foundation. If the Library as you\r\nreceived it does not specify a version number of the GNU Lesser\r\nGeneral Public License, you may choose any version of the GNU Lesser\r\nGeneral Public License ever published by the Free Software Foundation.\r\n\r\n If the Library as you received it specifies that a proxy can decide\r\nwhether future versions of the GNU Lesser General Public License shall\r\napply, that proxy's public statement of acceptance of any version is\r\npermanent authorization for you to choose that version for the\r\nLibrary.",
22 | "RelativeFilePath" : "",
23 | "VersionAsString" : "0.4.0.0",
24 | "LazCompatibility" : "1.6, 1.8, Trunk",
25 | "FPCCompatibility" : "3.2.0",
26 | "SupportedWidgetSet" : "non-gui component",
27 | "PackageType" : 3,
28 | "DependenciesAsString" : ""
29 | }
30 | ]
31 | }
--------------------------------------------------------------------------------
/opm/TwilioSMS.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MFernstrom/TwilioLib/c9328bf79be9396de451354593dc2ad18d33bf7e/opm/TwilioSMS.zip
--------------------------------------------------------------------------------
/testsms.pas:
--------------------------------------------------------------------------------
1 | program testsms.pas;
2 | {$mode objfpc}
3 | uses
4 | Sysutils, Classes, TwilioLib;
5 |
6 | procedure SendSMS;
7 | var
8 | twilio: TTwilio;
9 | twilio_result: TStrings;
10 | begin
11 | twilio_result := TStringList.Create;
12 | try
13 | twilio := TTwilio.create('your sid', 'your secret');
14 | try
15 | try
16 | twilio.send_sms('+OutPhone', '+ToPhone', 'message', twilio_result);
17 | except
18 | on E:ETWilioException do
19 | writeln(e.message)
20 | else raise;
21 | end;
22 | finally
23 | Twilio.Free;
24 | end;
25 | finally
26 | twilio_result.free;
27 | end;
28 | end;
29 |
30 | begin
31 | SendSMS;
32 | end.
33 |
--------------------------------------------------------------------------------
/testsms2.pas:
--------------------------------------------------------------------------------
1 | program testsms2.pas;
2 | {$mode objfpc}
3 | uses
4 | Sysutils, Classes, TwilioLib;
5 |
6 | procedure SendSMS;
7 | var
8 | twilio: ITwilio;
9 | twilio_result: TStrings;
10 | begin
11 | twilio_result := TStringList.Create;
12 | try
13 | twilio := TTwilio.create('', '') as ITwilio;
14 | try
15 | twilio.send_sms('', '', '', twilio_result);
16 | except
17 | on E:ETwilioException do
18 | writeln(e.message)
19 | else
20 | raise;
21 | end;
22 | finally
23 | twilio_result.free;
24 | end;
25 | end;
26 |
27 | begin
28 | SendSMS;
29 | end.
30 |
--------------------------------------------------------------------------------
/twilio.lpk:
--------------------------------------------------------------------------------
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 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
--------------------------------------------------------------------------------
/twilio.pas:
--------------------------------------------------------------------------------
1 | { This file was automatically created by Lazarus. Do not edit!
2 | This source is only used to compile and install the package.
3 | }
4 |
5 | unit twilio;
6 |
7 | {$warn 5023 off : no warning about unused units}
8 | interface
9 |
10 | uses
11 | TwilioLib;
12 |
13 | implementation
14 |
15 | end.
16 |
--------------------------------------------------------------------------------