Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/sachet/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/messagebird/sachet/provider/exotel"
"github.com/messagebird/sachet/provider/freemobile"
"github.com/messagebird/sachet/provider/ghasedak"
"github.com/messagebird/sachet/provider/gnokii"
"github.com/messagebird/sachet/provider/infobip"
"github.com/messagebird/sachet/provider/kannel"
"github.com/messagebird/sachet/provider/kavenegar"
Expand Down Expand Up @@ -77,6 +78,7 @@ var config struct {
Sfr sfr.Config
TextMagic textmagic.Config
Melipayamak melipayamak.Config
Gnokii gnokii.Config
}

Receivers []ReceiverConf
Expand Down
3 changes: 3 additions & 0 deletions cmd/sachet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/messagebird/sachet/provider/exotel"
"github.com/messagebird/sachet/provider/freemobile"
"github.com/messagebird/sachet/provider/ghasedak"
"github.com/messagebird/sachet/provider/gnokii"
"github.com/messagebird/sachet/provider/infobip"
"github.com/messagebird/sachet/provider/kannel"
"github.com/messagebird/sachet/provider/kavenegar"
Expand Down Expand Up @@ -150,6 +151,8 @@ func providerByName(name string) (sachet.Provider, error) {
return textmagic.NewTextMagic(config.Providers.TextMagic), nil
case "melipayamak":
return melipayamak.NewMelipayamak(config.Providers.Melipayamak), nil
case "gnokii":
return gnokii.NewGnokii(config.Providers.Gnokii), nil
}

return nil, fmt.Errorf("%s: Unknown provider", name)
Expand Down
11 changes: 9 additions & 2 deletions examples/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ providers:
no_stop_clause: true # True if you don't need STOP clause at the end on the message
tencentcloud:
region_id: ap-shanghai
secret_id: AKIDWqaCa1aNL3V0MtSG7mCZPjvrgJhqdgeN
secret_key: d5JLBreHfnfJjHbffWCsSoF8wYs5pNgl
secret_id: ''
secret_key: ''
app_id: 111233
sign_name: sign_name
template_code: 123233
Expand Down Expand Up @@ -108,6 +108,13 @@ providers:
username: '###'
password: '###'
endpoint: 'https://rest.payamak-panel.com/api/SendSMS/SendSMS'
gnokii:
# DB schema is based on /usr/share/doc/gnokii-smsd-mysql/sms.tables.mysql.sql
db_username: 'user'
db_password: ''
db_host: 'localhost'
db_port: 3306
db_name: 'smsd'

templates:
- telegram.tmpl
Expand Down
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1242
github.com/carlosdp/twiliogo v0.0.0-20161027183705-b26045ebb9d1
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/go-kit/kit v0.10.0 // indirect
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b // indirect
Expand Down Expand Up @@ -35,9 +34,14 @@ require (
gopkg.in/yaml.v2 v2.4.0
)

require github.com/textmagic/textmagic-rest-go-v2/v2 v2.0.1816
require (
github.com/go-sql-driver/mysql v1.8.1
github.com/stretchr/testify v1.7.0
github.com/textmagic/textmagic-rest-go-v2/v2 v2.0.1816
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/antihax/optional v1.0.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand All @@ -52,7 +56,6 @@ require (
github.com/prometheus/client_model v0.2.0 // indirect
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 // indirect
github.com/stretchr/testify v1.7.0 // indirect
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985 // indirect
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c // indirect
google.golang.org/appengine v1.6.6 // indirect
Expand Down
212 changes: 5 additions & 207 deletions go.sum

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions provider/gnokii/gnokii.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package gnokii

import (
"context"
"database/sql"
"fmt"
"log"

_ "github.com/go-sql-driver/mysql"

"github.com/messagebird/sachet"
)

// Config configuration struct for Gnokii Client.
type Config struct {
DbUsername string `yaml:"db_username"`
DbPassword string `yaml:"db_password"`
DbHost string `yaml:"db_host"`
DbPort int `yaml:"db_port"`
DbName string `yaml:"db_name"`
}

var _ (sachet.Provider) = (*Gnokii)(nil)

type Gnokii struct {
Config
Db *sql.DB
}

// NewGnokii creates a new Gnokii SMS client.
func NewGnokii(config Config) *Gnokii {
log.SetFlags(log.LstdFlags | log.Lshortfile)
dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", config.DbUsername, config.DbPassword, config.DbHost, config.DbPort, config.DbName)
db, err := sql.Open("mysql", dsn)
if err != nil {
log.Fatalf("Error while connecting to gnokii DB: %s", err)
}

gnokii := &Gnokii{config, db}
return gnokii
}

// Send send sms to n number of people using bulk sms api.
func (c *Gnokii) Send(message sachet.Message) error {
for _, recipient := range message.To {
query := "INSERT INTO `outbox` (`number`, `text`) VALUES (?, ?)"
_, err := c.Db.ExecContext(context.Background(), query, recipient, message.Text)
if err != nil {
return fmt.Errorf("Error while inserting sms into DB: %w", err)
}
}
return nil
}
27 changes: 27 additions & 0 deletions vendor/filippo.io/edwards25519/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions vendor/filippo.io/edwards25519/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions vendor/filippo.io/edwards25519/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading