Skip to content

Commit

Permalink
Merge pull request #66 from catawiki/ivdm-support-voice-messages
Browse files Browse the repository at this point in the history
Add support for voice messages to messagebird provider
  • Loading branch information
marcelcorso authored Oct 30, 2019
2 parents b818f95 + e35c3d5 commit c96ce38
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmd/sachet/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type ReceiverConf struct {
To []string
From string
Text string
Type string
}

var config struct {
Expand Down
1 change: 1 addition & 0 deletions cmd/sachet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func main() {
message := sachet.Message{
To: receiverConf.To,
From: receiverConf.From,
Type: receiverConf.Type,
Text: text,
}

Expand Down
43 changes: 43 additions & 0 deletions provider/messagebird/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# MessageBird
## Provider
To configure the MessageBird provider, you need to specify an access key.

```yaml
providers:
messagebird:
access_key: 'live_qKwVZ02ULV70GqabBYxLU8d5r'
debug: true
gateway: 240
language: en-us
voice: female
repeat: 2
```
The MessageBird provider supports text and voice messages.
For text messages you can configure the following parameters (see https://developers.messagebird.com/api/sms-messaging):
* `gateway`: an integer specifying the SMS gateway

For voice messages you can configure the following parameters (see https://developers.messagebird.com/api/voice-messaging/):
* `language`: specifies the language in which the message needs to be read to the recipient
* `voice`: specifies the voice in which the message needs to be read to the recipient
* `repeat`: specifies the number of times the message needs to be repeated

## Receivers
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.

```yaml
receivers:
- name: 'team1'
provider: messagebird
to:
- '+919742033616'
- '+919742033617'
type: voice
- name: 'team2'
provider: messagebird
to:
- '+919742033616'
- '+919742033617'
from: '08039591643'
type: text
```
24 changes: 21 additions & 3 deletions provider/messagebird/messagebird.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package messagebird
import (
"log"
"os"
"fmt"

"github.com/messagebird/go-rest-api"
"github.com/messagebird/sachet"
Expand All @@ -12,11 +13,15 @@ type MessageBirdConfig struct {
AccessKey string `yaml:"access_key"`
Gateway int `yaml:"gateway"`
Debug bool `yaml:"debug"`
Language string `yaml:"language"`
Voice string `yaml:"voice"`
Repeat int `yaml:"repeat"`
}

type MessageBird struct {
client *messagebird.Client
params messagebird.MessageParams
messageParams messagebird.MessageParams
voiceMessageParams messagebird.VoiceMessageParams
}

func NewMessageBird(config MessageBirdConfig) *MessageBird {
Expand All @@ -26,13 +31,26 @@ func NewMessageBird(config MessageBirdConfig) *MessageBird {
}
return &MessageBird{
client: client,
params: messagebird.MessageParams{
messageParams: messagebird.MessageParams{
Gateway: config.Gateway,
},
voiceMessageParams: messagebird.VoiceMessageParams{
Language: config.Language,
Voice: config.Voice,
Repeat: config.Repeat,
},
}
}

func (mb *MessageBird) Send(message sachet.Message) error {
_, err := mb.client.NewMessage(message.From, message.To, message.Text, &mb.params)
var err error=nil
switch message.Type {
case "","text":
_, err = mb.client.NewMessage(message.From, message.To, message.Text, &mb.messageParams)
case "voice":
_, err = mb.client.NewVoiceMessage(message.To, message.Text, &mb.voiceMessageParams)
default:
return fmt.Errorf("unknown message type %s", message.Type)
}
return err
}
1 change: 1 addition & 0 deletions sachet.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ type Message struct {
To []string
From string
Text string
Type string
}

0 comments on commit c96ce38

Please sign in to comment.