-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move SMPP notifier to Magistrala core
Signed-off-by: Dusan Borovcanin <[email protected]>
- Loading branch information
1 parent
14282fb
commit 8e64ac5
Showing
6 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# SMPP Notifier | ||
|
||
SMPP Notifier implements notifier for send SMS notifications. | ||
|
||
## Configuration | ||
|
||
The Subscription service using SMPP Notifier is configured using the environment variables presented in the | ||
following table. Note that any unset variables will be replaced with their | ||
default values. | ||
|
||
| Variable | Description | Default | | ||
| --------------------------------- | --------------------------------------------------------------------------------- | ------------------------------ | | ||
| MG_SMPP_NOTIFIER_LOG_LEVEL | Log level for SMPP Notifier (debug, info, warn, error) | info | | ||
| MG_SMPP_NOTIFIER_FROM_ADDRESS | From address for SMS notifications | | | ||
| MG_SMPP_NOTIFIER_CONFIG_PATH | Config file path with Message broker subjects list, payload type and content-type | /config.toml | | ||
| MG_SMPP_NOTIFIER_HTTP_HOST | Service HTTP host | localhost | | ||
| MG_SMPP_NOTIFIER_HTTP_PORT | Service HTTP port | 9014 | | ||
| MG_SMPP_NOTIFIER_HTTP_SERVER_CERT | Service HTTP server certificate path | "" | | ||
| MG_SMPP_NOTIFIER_HTTP_SERVER_KEY | Service HTTP server key | "" | | ||
| MG_SMPP_NOTIFIER_DB_HOST | Database host address | localhost | | ||
| MG_SMPP_NOTIFIER_DB_PORT | Database host port | 5432 | | ||
| MG_SMPP_NOTIFIER_DB_USER | Database user | magistrala | | ||
| MG_SMPP_NOTIFIER_DB_PASS | Database password | magistrala | | ||
| MG_SMPP_NOTIFIER_DB_NAME | Name of the database used by the service | subscriptions | | ||
| MG_SMPP_NOTIFIER_DB_SSL_MODE | DB connection SSL mode (disable, require, verify-ca, verify-full) | disable | | ||
| MG_SMPP_NOTIFIER_DB_SSL_CERT | Path to the PEM encoded certificate file | "" | | ||
| MG_SMPP_NOTIFIER_DB_SSL_KEY | Path to the PEM encoded key file | "" | | ||
| MG_SMPP_NOTIFIER_DB_SSL_ROOT_CERT | Path to the PEM encoded root certificate file | "" | | ||
| MG_SMPP_ADDRESS | SMPP address [host:port] | | | ||
| MG_SMPP_USERNAME | SMPP Username | | | ||
| MG_SMPP_PASSWORD | SMPP Password | | | ||
| MG_SMPP_SYSTEM_TYPE | SMPP System Type | | | ||
| MG_SMPP_SRC_ADDR_TON | SMPP source address TON | | | ||
| MG_SMPP_DST_ADDR_TON | SMPP destination address TON | | | ||
| MG_SMPP_SRC_ADDR_NPI | SMPP source address NPI | | | ||
| MG_SMPP_DST_ADDR_NPI | SMPP destination address NPI | | | ||
| MG_AUTH_GRPC_URL | Auth service gRPC URL | localhost:7001 | | ||
| MG_AUTH_GRPC_TIMEOUT | Auth service gRPC request timeout in seconds | 1s | | ||
| MG_AUTH_GRPC_CLIENT_TLS | Auth client TLS flag | false | | ||
| MG_AUTH_GRPC_CA_CERT | Path to Auth client CA certs in pem format | "" | | ||
| MG_MESSAGE_BROKER_URL | Message broker URL | nats://127.0.0.1:4222 | | ||
| MG_JAEGER_URL | Jaeger server URL | http://jaeger:14268/api/traces | | ||
| MG_SEND_TELEMETRY | Send telemetry to magistrala call home server | true | | ||
| MG_SMPP_NOTIFIER_INSTANCE_ID | SMPP Notifier instance ID | "" | | ||
|
||
## Usage | ||
|
||
Starting service will start consuming messages and sending SMS when a message is received. | ||
|
||
[doc]: https://docs.magistrala.abstractmachines.fr | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) Abstract Machines | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package smpp | ||
|
||
import ( | ||
"crypto/tls" | ||
) | ||
|
||
// Config represents SMPP transmitter configuration. | ||
type Config struct { | ||
Address string `env:"MG_SMPP_ADDRESS" envDefault:""` | ||
Username string `env:"MG_SMPP_USERNAME" envDefault:""` | ||
Password string `env:"MG_SMPP_PASSWORD" envDefault:""` | ||
SystemType string `env:"MG_SMPP_SYSTEM_TYPE" envDefault:""` | ||
SourceAddrTON uint8 `env:"MG_SMPP_SRC_ADDR_TON" envDefault:"0"` | ||
SourceAddrNPI uint8 `env:"MG_SMPP_DST_ADDR_TON" envDefault:"0"` | ||
DestAddrTON uint8 `env:"MG_SMPP_SRC_ADDR_NPI" envDefault:"0"` | ||
DestAddrNPI uint8 `env:"MG_SMPP_DST_ADDR_NPI" envDefault:"0"` | ||
TLS *tls.Config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright (c) Abstract Machines | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Package smpp contains the domain concept definitions needed to | ||
// support Magistrala SMS notifications. | ||
package smpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright (c) Abstract Machines | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package smpp | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/absmach/supermq/consumers/notifiers" | ||
"github.com/absmach/supermq/pkg/messaging" | ||
"github.com/absmach/supermq/pkg/transformers" | ||
"github.com/absmach/supermq/pkg/transformers/json" | ||
"github.com/fiorix/go-smpp/smpp" | ||
"github.com/fiorix/go-smpp/smpp/pdu/pdufield" | ||
"github.com/fiorix/go-smpp/smpp/pdu/pdutext" | ||
) | ||
|
||
var _ notifiers.Notifier = (*notifier)(nil) | ||
|
||
type notifier struct { | ||
transmitter *smpp.Transmitter | ||
transformer transformers.Transformer | ||
sourceAddrTON uint8 | ||
sourceAddrNPI uint8 | ||
destAddrTON uint8 | ||
destAddrNPI uint8 | ||
} | ||
|
||
// New instantiates SMTP message notifier. | ||
func New(cfg Config) notifiers.Notifier { | ||
t := &smpp.Transmitter{ | ||
Addr: cfg.Address, | ||
User: cfg.Username, | ||
Passwd: cfg.Password, | ||
SystemType: cfg.SystemType, | ||
RespTimeout: 3 * time.Second, | ||
} | ||
t.Bind() | ||
ret := ¬ifier{ | ||
transmitter: t, | ||
transformer: json.New([]json.TimeField{}), | ||
sourceAddrTON: cfg.SourceAddrTON, | ||
destAddrTON: cfg.DestAddrTON, | ||
sourceAddrNPI: cfg.SourceAddrNPI, | ||
destAddrNPI: cfg.DestAddrNPI, | ||
} | ||
return ret | ||
} | ||
|
||
func (n *notifier) Notify(from string, to []string, msg *messaging.Message) error { | ||
send := &smpp.ShortMessage{ | ||
Src: from, | ||
DstList: to, | ||
Validity: 10 * time.Minute, | ||
SourceAddrTON: n.sourceAddrTON, | ||
DestAddrTON: n.destAddrTON, | ||
SourceAddrNPI: n.sourceAddrNPI, | ||
DestAddrNPI: n.destAddrNPI, | ||
Text: pdutext.Raw(msg.GetPayload()), | ||
Register: pdufield.NoDeliveryReceipt, | ||
} | ||
_, err := n.transmitter.Submit(send) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters