Files
sigmasms/flash_call.go
2025-12-02 18:54:48 +03:00

47 lines
998 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}