47 lines
998 B
Go
47 lines
998 B
Go
package sigmasms
|
||
|
||
import (
|
||
"bytes"
|
||
"encoding/json"
|
||
"net/http"
|
||
)
|
||
|
||
type FlashCallRequest struct {
|
||
APIKey string `json:"api_key"`
|
||
Phone string `json:"phone"`
|
||
CodeLen int `json:"code_len"` // 4, 5, 6
|
||
}
|
||
|
||
type FlashCallResponse struct {
|
||
Status string `json:"status"`
|
||
CallID string `json:"call_id"`
|
||
From string `json:"from"` // номер, с которого звонили
|
||
Code string `json:"code"` // обычно это последние digits из from
|
||
}
|
||
|
||
func FlashCall(apiKey, phone string, codeLen int) (*FlashCallResponse, error) {
|
||
body := FlashCallRequest{
|
||
APIKey: apiKey,
|
||
Phone: phone,
|
||
CodeLen: codeLen,
|
||
}
|
||
|
||
data, _ := json.Marshal(body)
|
||
|
||
resp, err := http.Post(
|
||
"https://voice.sigmasms.ru/flashcall",
|
||
"application/json",
|
||
bytes.NewReader(data),
|
||
)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
defer resp.Body.Close()
|
||
|
||
var result FlashCallResponse
|
||
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||
return nil, err
|
||
}
|
||
return &result, nil
|
||
}
|