gitee.com/larksuite/oapi-sdk-go/v3@v3.0.3/event/model.go (about) 1 /* 2 * MIT License 3 * 4 * Copyright (c) 2022 Lark Technologies Pte. Ltd. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 * 8 * The above copyright notice and this permission notice, shall be included in all copies or substantial portions of the Software. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 11 */ 12 13 package larkevent 14 15 import ( 16 "net/http" 17 18 larkcore "gitee.com/larksuite/oapi-sdk-go/v3/core" 19 ) 20 21 type EventHeader struct { 22 EventID string `json:"event_id"` // 事件 ID 23 EventType string `json:"event_type"` // 事件类型 24 AppID string `json:"app_id"` // 应用 ID 25 TenantKey string `json:"tenant_key"` // 租户 Key 26 CreateTime string `json:"create_time"` // 事件创建时间戳(单位:毫秒) 27 Token string `json:"token"` // 事件 Token 28 } 29 30 type EventV1Header struct { 31 AppID string `json:"app_id"` // 应用 ID 32 OpenAppID string `json:"open_chat_id"` // Open App Id 33 OpenID string `json:"open_id"` // Open Id 34 TenantKey string `json:"tenant_key"` // 租户 Key 35 Type string `json:"type"` // event_callback-事件推送,url_verification-url地址验证 36 } 37 38 type EventV2Base struct { 39 Schema string `json:"schema"` // 事件模式 40 Header *EventHeader `json:"header"` // 事件头 41 } 42 43 func (base *EventV2Base) TenantKey() string { 44 if base != nil && base.Header != nil { 45 return base.Header.TenantKey 46 } 47 return "" 48 } 49 50 type EventV2Body struct { 51 EventV2Base 52 Challenge string `json:"challenge"` 53 Event interface{} `json:"event"` 54 Type string `json:"type"` 55 } 56 57 type EventReq struct { 58 Header map[string][]string 59 Body []byte 60 RequestURI string 61 } 62 63 func (req *EventReq) RequestId() string { 64 logID := req.Header[larkcore.HttpHeaderKeyLogId] 65 if len(logID) > 0 { 66 return logID[0] 67 } 68 logID = req.Header[larkcore.HttpHeaderKeyRequestId] 69 if len(logID) > 0 { 70 return logID[0] 71 } 72 return "" 73 } 74 75 type EventResp struct { 76 Header http.Header // http请求 header 77 Body []byte // http请求 body 78 StatusCode int // http请求状态码 79 } 80 81 type EventBase struct { 82 Ts string `json:"ts"` // 事件发送的时间,一般近似于事件发生的时间。 83 UUID string `json:"uuid"` // 事件的唯一标识 84 Token string `json:"token"` // 即Verification Token 85 Type string `json:"type"` // event_callback-事件推送,url_verification-url地址验证 86 } 87 88 type EventEncryptMsg struct { 89 Encrypt string `json:"encrypt"` 90 } 91 92 type EventFuzzy struct { 93 Encrypt string `json:"encrypt"` 94 Schema string `json:"schema"` 95 Token string `json:"token"` 96 Type string `json:"type"` 97 Challenge string `json:"challenge"` 98 Header *EventHeader `json:"header"` 99 Event *struct { 100 Type interface{} `json:"type"` 101 } `json:"event"` 102 } 103 104 const ( 105 EventRequestNonce = "X-Lark-Request-Nonce" 106 EventRequestTimestamp = "X-Lark-Request-Timestamp" 107 EventSignature = "X-Lark-Signature" 108 ) 109 110 type ReqType string 111 112 const ( 113 ReqTypeChallenge ReqType = "url_verification" 114 ReqTypeEventCallBack ReqType = "event_callback" 115 ) 116 117 const userAgentHeader = "User-Agent" 118 const ContentTypeHeader = "Content-Type" 119 const ContentTypeJson = "application/json" 120 const DefaultContentType = ContentTypeJson + "; charset=utf-8" 121 const WebhookResponseFormat = `{"msg":"%s"}` 122 const ChallengeResponseFormat = `{"challenge":"%s"}`