-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjson.go
More file actions
45 lines (36 loc) · 1018 Bytes
/
json.go
File metadata and controls
45 lines (36 loc) · 1018 Bytes
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
package main
import (
"encoding/json"
"log"
"github.com/AshokShau/gotdbot"
)
func printJsonHandler(c *gotdbot.Client, ctx *gotdbot.Context) error {
if ctx.EffectiveMessage != nil && ctx.EffectiveMessage.IsOutgoing {
return gotdbot.EndGroups
}
if chatID := ctx.EffectiveChatId; chatID != 0 && !isDebugEnabled(chatID) {
return nil
}
data, marshalErr := json.MarshalIndent(ctx.RawUpdate, "", " ")
if marshalErr != nil {
log.Printf("[ERROR] Failed to marshal update: %v", marshalErr)
return nil
}
jsonStr := string(data)
chatID := ctx.EffectiveChatId
if chatID == 0 {
log.Printf("[UPDATE] type=%s\n%s", ctx.RawUpdate.GetType(), jsonStr)
return nil
}
guest := ctx.Update.UpdateNewGuestQuery
if guest != nil {
if err := sendResult(c, guest.Id, jsonStr); err != nil {
log.Printf("[ERROR] Failed to send JSON for guest query: %v", err)
}
return nil
}
if err := sendJSON(c, chatID, 0, jsonStr); err != nil {
log.Printf("[ERROR] Failed to send JSON: %v", err)
}
return nil
}