From a04166bec7fedd27b82bb50cd812ada70bfdc118 Mon Sep 17 00:00:00 2001 From: Julian Einwag Date: Thu, 18 Oct 2018 10:47:40 +0200 Subject: [PATCH] support for smstools --- cmd/sachet/config.go | 2 ++ cmd/sachet/main.go | 3 +++ provider/smstools/smstools.go | 36 +++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 provider/smstools/smstools.go diff --git a/cmd/sachet/config.go b/cmd/sachet/config.go index 3c5fef9..caaf7b6 100644 --- a/cmd/sachet/config.go +++ b/cmd/sachet/config.go @@ -13,6 +13,7 @@ import ( "github.com/messagebird/sachet/provider/nexmo" "github.com/messagebird/sachet/provider/otc" "github.com/messagebird/sachet/provider/sipgate" + "github.com/messagebird/sachet/provider/smstools" "github.com/messagebird/sachet/provider/telegram" "github.com/messagebird/sachet/provider/turbosms" "github.com/messagebird/sachet/provider/twilio" @@ -44,6 +45,7 @@ var config struct { FreeMobile freemobile.Config AspSms aspsms.Config Sipgate sipgate.Config + SmsTools smstools.SmsToolsConfig } Receivers []ReceiverConf diff --git a/cmd/sachet/main.go b/cmd/sachet/main.go index 840489e..48935de 100644 --- a/cmd/sachet/main.go +++ b/cmd/sachet/main.go @@ -21,6 +21,7 @@ import ( "github.com/messagebird/sachet/provider/nexmo" "github.com/messagebird/sachet/provider/otc" "github.com/messagebird/sachet/provider/sipgate" + "github.com/messagebird/sachet/provider/smstools" "github.com/messagebird/sachet/provider/telegram" "github.com/messagebird/sachet/provider/turbosms" "github.com/messagebird/sachet/provider/twilio" @@ -174,6 +175,8 @@ func providerByName(name string) (sachet.Provider, error) { return aspsms.NewAspSms(config.Providers.AspSms), nil case "sipgate": return sipgate.NewSipgate(config.Providers.Sipgate), nil + case "smstools": + return smstools.NewSmsTools(config.Providers.SmsTools), nil } return nil, fmt.Errorf("%s: Unknown provider", name) diff --git a/provider/smstools/smstools.go b/provider/smstools/smstools.go new file mode 100644 index 0000000..3bc13ea --- /dev/null +++ b/provider/smstools/smstools.go @@ -0,0 +1,36 @@ +package smstools + +import ( + "io/ioutil" + + "github.com/messagebird/sachet" +) + +type SmsToolsConfig struct { + OutgoingDir string `yaml:"outgoing_dir"` +} + +type SmsTools struct { + SmsToolsConfig +} + +func NewSmsTools(config SmsToolsConfig) *SmsTools { + SmsTools := &SmsTools{SmsToolsConfig: config} + return SmsTools +} + +func (smst *SmsTools) Send(message sachet.Message) error { + for _, recipient := range message.To { + outfile, err := ioutil.TempFile(smst.OutgoingDir, "sachet-") + if err != nil { + return err + } + defer outfile.Close() + outfile.WriteString("To: " + recipient + "\n") + _, err = outfile.WriteString(message.Text) + if err != nil { + return err + } + } + return nil +}