diff --git a/cmd/sachet/config.go b/cmd/sachet/config.go index 7c034d9..02f3b62 100644 --- a/cmd/sachet/config.go +++ b/cmd/sachet/config.go @@ -28,6 +28,7 @@ type ReceiverConf struct { To []string From string Text string + Type string } var config struct { diff --git a/cmd/sachet/main.go b/cmd/sachet/main.go index 6683f56..f577687 100644 --- a/cmd/sachet/main.go +++ b/cmd/sachet/main.go @@ -106,6 +106,7 @@ func main() { message := sachet.Message{ To: receiverConf.To, From: receiverConf.From, + Type: receiverConf.Type, Text: text, } diff --git a/provider/messagebird/README.md b/provider/messagebird/README.md new file mode 100644 index 0000000..87232cf --- /dev/null +++ b/provider/messagebird/README.md @@ -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 +``` diff --git a/provider/messagebird/messagebird.go b/provider/messagebird/messagebird.go index 87a1be2..21bbde1 100644 --- a/provider/messagebird/messagebird.go +++ b/provider/messagebird/messagebird.go @@ -3,6 +3,7 @@ package messagebird import ( "log" "os" + "fmt" "github.com/messagebird/go-rest-api" "github.com/messagebird/sachet" @@ -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 { @@ -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 } diff --git a/sachet.go b/sachet.go index 3ac55a2..336267c 100644 --- a/sachet.go +++ b/sachet.go @@ -8,4 +8,5 @@ type Message struct { To []string From string Text string + Type string }