sms completed

This commit is contained in:
Vladimir V Maksimov
2025-12-03 18:34:25 +03:00
parent d7bd28b759
commit 85cbc3e940
4 changed files with 171 additions and 9 deletions

42
sms.go
View File

@@ -1,7 +1,9 @@
package sigmasms
import (
"fmt"
"log"
"time"
"github.com/google/uuid"
)
@@ -50,7 +52,7 @@ func SendSMS(apiKey, phone, sender, text string) (*SendSMSResponse, error) {
},
}
resp := make(map[string]any)
var resp SendSMSResponse
err := requestPost(
"https://user.sigmasms.ru/api/sendings",
@@ -63,7 +65,39 @@ func SendSMS(apiKey, phone, sender, text string) (*SendSMSResponse, error) {
return nil, err
}
log.Println(resp)
return nil, nil
return &resp, nil
}
func SendSMSWait(apiKey, phone, sender, text string) (transactionID uuid.UUID, err error) {
var resp *SendSMSResponse
if resp, err = SendSMS(apiKey, phone, sender, text); err != nil {
log.Println(err)
return
} else {
if resp.Status == "failed" {
err = fmt.Errorf("sms send error: %s", resp.Error)
return
}
transactionID = resp.ID
var sResp *StatusResponse
mainLoop:
for resp.Status == "pending" {
time.Sleep(time.Millisecond * 100)
sResp, err = RequestStatus(resp.ID, apiKey)
log.Println(sResp.State.Status, err)
if err != nil {
return
}
resp.Status = sResp.State.Status
switch resp.Status {
case "pending", "sent":
continue mainLoop
case "seen", "delivered":
return
default:
err = fmt.Errorf("sms status: %s", sResp.State.Status)
}
}
}
return
}