-
Notifications
You must be signed in to change notification settings - Fork 25
/
url_scheme.go
197 lines (169 loc) · 4.66 KB
/
url_scheme.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
package bot
import (
"encoding/base64"
"net/url"
"github.com/MixinNetwork/go-number"
)
const _urlScheme = "mixin"
// SchemeUsers scheme of a user
//
// userId required
//
// https://developers.mixin.one/docs/schema#popups-user-profile
func SchemeUsers(userId string) string {
u := url.URL{
Scheme: _urlScheme,
Host: "users",
Path: userId,
}
return u.String()
}
// SchemeTransfer scheme of a transfer
//
// userId required
//
// https://developers.mixin.one/docs/schema#invoke-transfer-page
func SchemeTransfer(userId string) string {
u := url.URL{
Scheme: _urlScheme,
Host: "transfer",
Path: userId,
}
return u.String()
}
// SchemePay scheme of a pay
//
// assetId required
// recipientId required, receiver's user id
// amount require, transfer amount
// traceId optional, UUID, prevent duplicate payment
// memo optional, transaction memo
//
// https://developers.mixin.one/docs/schema#invoke-payment-page
func SchemePay(assetId, traceId, recipientId, memo string, amount number.Decimal) string {
q := url.Values{}
q.Set("asset", assetId)
q.Set("trace", traceId)
q.Set("amount", amount.String())
q.Set("recipient", recipientId)
q.Set("memo", memo)
u := url.URL{
Scheme: _urlScheme,
Host: "pay",
RawQuery: q.Encode(),
}
return u.String()
}
// SchemeCodes scheme of a code
//
// code required
//
// https://developers.mixin.one/docs/schema#popus-code-info
func SchemeCodes(codeId string) string {
u := url.URL{
Scheme: _urlScheme,
Host: "codes",
Path: codeId,
}
return u.String()
}
// SchemeSnapshots scheme of a snapshot
//
// snapshotId required if no traceId
// traceId required if no snapshotId
//
// https://developers.mixin.one/docs/schema#transfer-details-interface
func SchemeSnapshots(snapshotId, traceId string) string {
u := url.URL{
Scheme: _urlScheme,
Host: "snapshots",
}
if snapshotId != "" {
u.Path = snapshotId
}
if traceId != "" {
query := url.Values{}
query.Set("trace", traceId)
u.RawQuery = query.Encode()
}
return u.String()
}
// SchemeConversations scheme of a conversation
//
// userID optional, for user conversation only, if there's not conversation with the user, messenger will create the conversation first
//
// https://developers.mixin.one/docs/schema#open-an-conversation
func SchemeConversations(conversationID, userID string) string {
u := url.URL{
Scheme: _urlScheme,
Host: "conversations",
}
if conversationID != "" {
u.Path = conversationID
}
if userID != "" {
query := url.Values{}
query.Set("user", userID)
u.RawQuery = query.Encode()
}
return u.String()
}
// SchemeApps scheme of an app
//
// appID required, userID of an app
// action optional, action about this scheme, default is "open"
// params optional, parameters of any name or type can be passed when opening the bot homepage to facilitate the development of features like invitation codes, visitor tracking, etc
//
// https://developers.mixin.one/docs/schema#popups-bot-profile
func SchemeApps(appID, action string, params map[string]string) string {
u := url.URL{
Scheme: _urlScheme,
Host: "apps",
}
if appID != "" {
u.Path = appID
}
query := url.Values{}
if action != "" {
query.Set("action", action)
} else {
query.Set("action", "open")
}
for k, v := range params {
query.Set(k, v)
}
u.RawQuery = query.Encode()
return u.String()
}
type SendSchemeCategory = string
const (
SendSchemeCategoryText SendSchemeCategory = "text"
SendSchemeCategoryImage SendSchemeCategory = "image"
SendSchemeCategoryContact SendSchemeCategory = "contact"
SendSchemeCategoryAppCard SendSchemeCategory = "app_card"
SendSchemeCategoryLive SendSchemeCategory = "live"
SendSchemeCategoryPost SendSchemeCategory = "post"
)
// SchemeSend scheme of a share
//
// category required, category of shared content
// data required, shared content
// conversationID optional, If you specify conversation and it is the conversation of the user's current session, the confirmation box shown above will appear, the message will be sent after the user clicks the confirmation; if the conversation is not specified or is not the conversation of the current session, an interface where the user chooses which session to share with will show up.
//
// https://developers.mixin.one/docs/schema#sharing
func SchemeSend(category SendSchemeCategory, data []byte, conversationID string) string {
u := url.URL{
Scheme: _urlScheme,
Host: "send",
}
query := url.Values{}
query.Set("category", category)
if len(data) > 0 {
query.Set("data", url.QueryEscape(base64.StdEncoding.EncodeToString(data)))
}
if conversationID != "" {
query.Set("conversation", conversationID)
}
u.RawQuery = query.Encode()
return u.String()
}