-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwiraya.go
147 lines (112 loc) · 3.02 KB
/
wiraya.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package gowiraya
import (
"crypto/tls"
"fmt"
"net/http"
"net/url"
)
const (
ErrorSender = "ERROR_SENDER"
ErrorContent = "ERROR_CONTENT"
ErrorDateTime = "ERROR_DATETIME"
ErrorAuthentication = "ERROR_AUTHENTICATION"
ErrorProjectNotFound = "ERROR_PROJECT_NOT_FOUND"
StatusInqueue = "INQUEUE"
StatusSent = "SENT"
StatusDelivered = "DELIVERED"
StatusNotDelivered = "NOT DELIVERED"
StatusTooLate = "TOOLATE"
StatusFailure = "FAILURE"
)
type WirayaClient struct {
HttpClientProxy *http.Client
HttpClient *http.Client
baseUrlNewApi string
baseUrlOldApi string
xApiKey string
}
func NewWirayaClient(xApiKey string, proxy *string) (client *WirayaClient, err error) {
httpClientProxy := http.DefaultClient
httpClient := http.DefaultClient
if proxy != nil {
proxyURL, err := url.Parse(*proxy)
if err != nil {
return nil, err
}
transport := http.Transport{
Proxy: http.ProxyURL(proxyURL),
TLSClientConfig: &tls.Config{},
}
httpClientProxy.Transport = &transport
}
client = &WirayaClient{
HttpClientProxy: httpClientProxy,
HttpClient: httpClient,
baseUrlOldApi: "https://api.wiraya.com",
baseUrlNewApi: "https://api.wiraya.ai",
xApiKey: xApiKey,
}
return
}
//
// OLD api endpoints
//
func (c *WirayaClient) SendMessageFromAlpha(data SendMessage) (response Response, err error) {
endpoint := "/api/SendMessageFromAlpha/json"
err = c.apiPostOld(endpoint, data, &response)
if err != nil {
return
}
return
}
func (c *WirayaClient) GetMessageStatus(data MessageStatus) (response Response, err error) {
endpoint := "/api/GetMessageStatus/json"
err = c.apiPostOld(endpoint, data, &response)
if err != nil {
return
}
return
}
func (c *WirayaClient) VerifyCode(data VerifyPinCode) (response Response, err error) {
endpoint := "/api/VerifyCode/json"
err = c.apiPostOld(endpoint, data, &response)
if err != nil {
return
}
return
}
func (c *WirayaClient) SendPinCode(data SendPinCode) (response Response, err error) {
endpoint := "/api/SendPinCode/json"
err = c.apiPostOld(endpoint, data, &response)
if err != nil {
return
}
return
}
//
// NEW api endpoints
//
func (c *WirayaClient) AddContact(contactID int64, data ContactRequstModel) (response ActionResponseWithId, err error) {
endpoint := fmt.Sprintf("/api/Contact/%d", contactID)
err = c.apiCallNew(http.MethodPut, endpoint, data, &response)
if err != nil {
return
}
return
}
func (c *WirayaClient) AddContactToCampaign(contactID int64, data CampaignRequestModel) (response IdResponse, err error) {
endpoint := fmt.Sprintf("/api/Contact/%d/campaigns", contactID)
err = c.apiCallNew(http.MethodPost, endpoint, data, &response)
if err != nil {
return
}
return
}
func (c *WirayaClient) AddEventToContact(contactID int64, data EventRequestModel) (response IdResponse, err error) {
endpoint := fmt.Sprintf("/api/Contact/%d/events", contactID)
err = c.apiCallNew(http.MethodPut, endpoint, data, &response)
if err != nil {
return
}
return
}