in progress
This commit is contained in:
69
sms.go
Normal file
69
sms.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package sigmasms
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
/*
|
||||
{
|
||||
"recipient": "+79999999999",
|
||||
"type": "sms",
|
||||
"payload": {
|
||||
"sender": "Имя отправителя",
|
||||
"text": "Текст сообщения"
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
var (
|
||||
TypeSMS = "sms"
|
||||
)
|
||||
|
||||
type Payload struct {
|
||||
Sender string `json:"sender"`
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
type SendSMSResponse struct {
|
||||
Error string `json:"error"`
|
||||
ID uuid.UUID `json:"id"`
|
||||
Price float64 `json:"price"`
|
||||
Recepient string `json:"recipient"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type SendSMSRequest struct {
|
||||
Recepient string `json:"recipient"`
|
||||
Type string `json:"type"`
|
||||
Payload Payload `json:"payload"`
|
||||
}
|
||||
|
||||
func SendSMS(apiKey, phone, sender, text string) (*SendSMSResponse, error) {
|
||||
req := SendSMSRequest{
|
||||
Recepient: phone,
|
||||
Type: TypeSMS,
|
||||
Payload: Payload{
|
||||
Sender: sender,
|
||||
Text: text,
|
||||
},
|
||||
}
|
||||
|
||||
resp := make(map[string]any)
|
||||
|
||||
err := requestPost(
|
||||
"https://user.sigmasms.ru/api/sendings",
|
||||
apiKey,
|
||||
&req,
|
||||
&resp,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Println(resp)
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
Reference in New Issue
Block a user