Skip to content

Commit bf70507

Browse files
committed
Add help text for --help. Added -f to change FROM field.
1 parent 0353921 commit bf70507

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

send_sms.pl

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,27 @@
99

1010
my %config;
1111

12+
sub HELP_MESSAGE {
13+
print $0 . ' - Perl implementation of the Telstra Messaging API v2
14+
Options:
15+
-n The number to send an SMS to formatted as: +61400000000
16+
If not specified, prompted for input.
17+
18+
-m If specified, the message to send - otherwise prompted for input.
19+
20+
-f If specified, will change the From text on your message. Requires
21+
account support within the API.
22+
';
23+
exit 0;
24+
}
25+
1226
if ( -f dirname($0) . "/tokenstore.bin" ) {
1327
%config = %{ retrieve(dirname($0) . "/tokenstore.bin") };
1428
}
1529

1630
## Check if we have any command line options, if not, prompt for input.
1731
my %options;
18-
getopts('n:m:', \%options);
32+
getopts('f:n:m:', \%options);
1933

2034
## If a number isn't provided with -n, prompt for destination number.
2135
if ( ! $options{n} ) {
@@ -38,14 +52,21 @@
3852
'body' => $options{m},
3953
);
4054

55+
## If we specified a From using -f, provide it in the body
56+
if ( $options{f} ) {
57+
$body{'from'} = $options{f};
58+
}
59+
4160
## Get an OAuth token if required.
4261
get_token(%config);
4362

4463
my $req = HTTP::Request->new( 'POST', 'https://tapi.telstra.com/v2/messages/sms' );
4564
$req->header( 'Content-Type' => 'application/json' );
4665
$req->header( 'Authorization' => 'Bearer ' . $config{token} );
4766
$req->content( to_json(\%body) );
67+
print "Sending: " . $req->content() . "\n";
4868

4969
my $ua = LWP::UserAgent->new;
5070
my $res = $ua->request($req);
5171
print "Result: " . $res->status_line . "\n";
72+
print $res->decoded_content . "\n";

0 commit comments

Comments
 (0)