in progress
This commit is contained in:
46
flash_call.go
Normal file
46
flash_call.go
Normal file
@@ -0,0 +1,46 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user