Skip to content

Commit 6e70b27

Browse files
committed
add voice
1 parent 1910383 commit 6e70b27

File tree

6 files changed

+76
-7
lines changed

6 files changed

+76
-7
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 1.1.0
2+
3+
- Add voice
4+
- Improve error handling
5+
16
# 1.0.0
27

38
- Initial release

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ configuration in `/opt/stackstorm/configs/` by running `st2ctl reload --register
2424

2525
## Actions
2626

27-
- **send_sms** - Action which sends an SMS using sms77 API.
28-
`st2 run sms77.send_sms to=01716992343 text=HI2U from=StackStorm`
27+
- **send_sms** - Action which sends SMS. Multiple recipients can be separated by comma.
28+
`st2 run sms77.send_sms to="01716992343,491771783130" text=HI2U from=StackStorm`
29+
30+
- **send_voice** - Action which makes a text-to-speech call using sms77 API.
31+
`st2 run sms77.send_voice to=+491716992343 text='Dear sir or madam' from=+13134378004 xml=false`
2932

3033
### Support
3134

actions/send_sms.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ def __init__(self, config=None, action_service=None):
99
self.client = Sms77api(self.config['api_key'])
1010

1111
def run(self, to, text, **kwargs):
12-
try:
13-
self.client.sms(to, text, kwargs)
14-
except Exception as e:
15-
error_msg = ('Failed sending sms to: %s, exception: %s\n' % (to, str(e)))
12+
def on_error(ex):
13+
error_msg = ('Failed sending sms to: %s, exception: %s\n' % (to, str(ex)))
1614
self.logger.error(error_msg)
1715
raise Exception(error_msg)
1816

17+
try:
18+
res = self.client.sms(to, text, kwargs)
19+
if int(res) not in [100, 101]:
20+
on_error(Exception(res))
21+
22+
except Exception as e:
23+
on_error(e)
24+
1925
self.logger.info('Successfully sent sms to: %s\n' % to)

actions/send_voice.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from sms77api.Sms77api import Sms77api
2+
3+
from st2common.runners.base_action import Action
4+
5+
6+
class Sms77SendVoiceAction(Action):
7+
def __init__(self, config=None, action_service=None):
8+
super(Sms77SendVoiceAction, self).__init__(config, action_service)
9+
self.client = Sms77api(self.config['api_key'])
10+
11+
def run(self, to, text, **kwargs):
12+
def on_error(ex):
13+
error_msg = ('Failed sending voice to: %s, exception: %s\n' % (to, str(ex)))
14+
self.logger.error(error_msg)
15+
raise Exception(error_msg)
16+
17+
try:
18+
res = self.client.voice(
19+
to, text, kwargs.get('xml', False), kwargs.get('from', None))
20+
lines = res.splitlines()
21+
code = lines[0]
22+
if 100 != int(code):
23+
on_error(Exception(code))
24+
25+
except Exception as e:
26+
on_error(e)
27+
28+
self.logger.info('Successfully sent voice to: %s\n' % to)

actions/send_voice.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
description: This makes a text-to-speech call using sms77.
3+
enabled: true
4+
entry_point: send_voice.py
5+
name: send_voice
6+
parameters:
7+
from:
8+
description: Caller ID - must be a shared inbound number or a verified one.
9+
position: 2
10+
required: false
11+
type: string
12+
xml:
13+
description: Specifies whether the text is of XML format or plain text.
14+
position: 3
15+
required: false
16+
type: boolean
17+
text:
18+
description: Body of the message.
19+
position: 1
20+
required: true
21+
type: string
22+
to:
23+
description: Recipient number in E.164 format. Example +14151234567.
24+
position: 0
25+
required: true
26+
type: string
27+
runner_type: python-script

pack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ name: sms77
66
ref: sms77
77
python_versions:
88
- "3"
9-
version: 1.0.0
9+
version: 1.1.0

0 commit comments

Comments
 (0)