|
26 | 26 | FeishuPayload struct { |
27 | 27 | Timestamp int64 `json:"timestamp,omitempty"` // Unix timestamp for signature verification |
28 | 28 | Sign string `json:"sign,omitempty"` // Signature for verification |
29 | | - MsgType string `json:"msg_type"` // text / post / image / share_chat / interactive / file /audio / media |
| 29 | + MsgType string `json:"msg_type"` // text / post / image / share_chat / interactive / file /audio / media |
30 | 30 | Content struct { |
31 | 31 | Text string `json:"text"` |
32 | 32 | } `json:"content"` |
@@ -204,44 +204,44 @@ func GenSign(secret string, timestamp int64) (string, error) { |
204 | 204 |
|
205 | 205 | func newFeishuRequest(_ context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) { |
206 | 206 | var pc payloadConvertor[FeishuPayload] = feishuConvertor{} |
207 | | - |
| 207 | + |
208 | 208 | // Get the payload first |
209 | 209 | payload, err := newPayload(pc, []byte(t.PayloadContent), t.EventType) |
210 | 210 | if err != nil { |
211 | 211 | return nil, nil, err |
212 | 212 | } |
213 | | - |
| 213 | + |
214 | 214 | // Add timestamp and signature if secret is provided |
215 | 215 | if w.Secret != "" { |
216 | 216 | timestamp := time.Now().Unix() |
217 | 217 | payload.Timestamp = timestamp |
218 | | - |
| 218 | + |
219 | 219 | // Generate signature |
220 | 220 | sign, err := GenSign(w.Secret, timestamp) |
221 | 221 | if err != nil { |
222 | 222 | return nil, nil, err |
223 | 223 | } |
224 | 224 | payload.Sign = sign |
225 | 225 | } |
226 | | - |
| 226 | + |
227 | 227 | // Marshal the payload |
228 | 228 | body, err := json.MarshalIndent(payload, "", " ") |
229 | 229 | if err != nil { |
230 | 230 | return nil, nil, err |
231 | 231 | } |
232 | | - |
| 232 | + |
233 | 233 | // Create the request |
234 | 234 | method := w.HTTPMethod |
235 | 235 | if method == "" { |
236 | 236 | method = http.MethodPost |
237 | 237 | } |
238 | | - |
| 238 | + |
239 | 239 | req, err := http.NewRequest(method, w.URL, bytes.NewReader(body)) |
240 | 240 | if err != nil { |
241 | 241 | return nil, nil, err |
242 | 242 | } |
243 | 243 | req.Header.Set("Content-Type", "application/json") |
244 | | - |
| 244 | + |
245 | 245 | // Add default headers |
246 | 246 | return req, body, addDefaultHeaders(req, []byte(w.Secret), w, t, body) |
247 | 247 | } |
|
0 commit comments