Skip to content

Commit c96ce38

Browse files
authored
Merge pull request #66 from catawiki/ivdm-support-voice-messages
Add support for voice messages to messagebird provider
2 parents b818f95 + e35c3d5 commit c96ce38

File tree

5 files changed

+67
-3
lines changed

5 files changed

+67
-3
lines changed

cmd/sachet/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type ReceiverConf struct {
2828
To []string
2929
From string
3030
Text string
31+
Type string
3132
}
3233

3334
var config struct {

cmd/sachet/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ func main() {
106106
message := sachet.Message{
107107
To: receiverConf.To,
108108
From: receiverConf.From,
109+
Type: receiverConf.Type,
109110
Text: text,
110111
}
111112

provider/messagebird/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# MessageBird
2+
## Provider
3+
To configure the MessageBird provider, you need to specify an access key.
4+
5+
```yaml
6+
providers:
7+
messagebird:
8+
access_key: 'live_qKwVZ02ULV70GqabBYxLU8d5r'
9+
debug: true
10+
gateway: 240
11+
language: en-us
12+
voice: female
13+
repeat: 2
14+
```
15+
16+
The MessageBird provider supports text and voice messages.
17+
For text messages you can configure the following parameters (see https://developers.messagebird.com/api/sms-messaging):
18+
* `gateway`: an integer specifying the SMS gateway
19+
20+
For voice messages you can configure the following parameters (see https://developers.messagebird.com/api/voice-messaging/):
21+
* `language`: specifies the language in which the message needs to be read to the recipient
22+
* `voice`: specifies the voice in which the message needs to be read to the recipient
23+
* `repeat`: specifies the number of times the message needs to be repeated
24+
25+
## Receivers
26+
To configure a MessageBird receiver you must specify a list of targets. By default text messages are send, but you can specify a voice message by setting `type: voice` for a receiver. The `type` defaults to `text`. The `from` field is not used for voice messages.
27+
28+
```yaml
29+
receivers:
30+
- name: 'team1'
31+
provider: messagebird
32+
to:
33+
- '+919742033616'
34+
- '+919742033617'
35+
type: voice
36+
- name: 'team2'
37+
provider: messagebird
38+
to:
39+
- '+919742033616'
40+
- '+919742033617'
41+
from: '08039591643'
42+
type: text
43+
```

provider/messagebird/messagebird.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package messagebird
33
import (
44
"log"
55
"os"
6+
"fmt"
67

78
"github.com/messagebird/go-rest-api"
89
"github.com/messagebird/sachet"
@@ -12,11 +13,15 @@ type MessageBirdConfig struct {
1213
AccessKey string `yaml:"access_key"`
1314
Gateway int `yaml:"gateway"`
1415
Debug bool `yaml:"debug"`
16+
Language string `yaml:"language"`
17+
Voice string `yaml:"voice"`
18+
Repeat int `yaml:"repeat"`
1519
}
1620

1721
type MessageBird struct {
1822
client *messagebird.Client
19-
params messagebird.MessageParams
23+
messageParams messagebird.MessageParams
24+
voiceMessageParams messagebird.VoiceMessageParams
2025
}
2126

2227
func NewMessageBird(config MessageBirdConfig) *MessageBird {
@@ -26,13 +31,26 @@ func NewMessageBird(config MessageBirdConfig) *MessageBird {
2631
}
2732
return &MessageBird{
2833
client: client,
29-
params: messagebird.MessageParams{
34+
messageParams: messagebird.MessageParams{
3035
Gateway: config.Gateway,
3136
},
37+
voiceMessageParams: messagebird.VoiceMessageParams{
38+
Language: config.Language,
39+
Voice: config.Voice,
40+
Repeat: config.Repeat,
41+
},
3242
}
3343
}
3444

3545
func (mb *MessageBird) Send(message sachet.Message) error {
36-
_, err := mb.client.NewMessage(message.From, message.To, message.Text, &mb.params)
46+
var err error=nil
47+
switch message.Type {
48+
case "","text":
49+
_, err = mb.client.NewMessage(message.From, message.To, message.Text, &mb.messageParams)
50+
case "voice":
51+
_, err = mb.client.NewVoiceMessage(message.To, message.Text, &mb.voiceMessageParams)
52+
default:
53+
return fmt.Errorf("unknown message type %s", message.Type)
54+
}
3755
return err
3856
}

sachet.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ type Message struct {
88
To []string
99
From string
1010
Text string
11+
Type string
1112
}

0 commit comments

Comments
 (0)