-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjson.go
More file actions
60 lines (50 loc) · 1.39 KB
/
Copy pathjson.go
File metadata and controls
60 lines (50 loc) · 1.39 KB
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
package main
import (
"encoding/json"
"github.com/AshokShau/gotdbot"
)
func printJsonHandler(c *gotdbot.Client, update gotdbot.TlObject) error {
var chatID int64
var messageID int64
var isOutgoing bool
switch u := update.(type) {
case *gotdbot.UpdateNewMessage:
chatID = u.Message.ChatId
messageID = u.Message.Id
isOutgoing = u.Message.IsOutgoing
case *gotdbot.UpdateNewBusinessMessage:
chatID = u.Message.Message.ChatId
messageID = u.Message.Message.Id
isOutgoing = u.Message.Message.IsOutgoing
case *gotdbot.UpdateBusinessMessageEdited:
chatID = u.Message.Message.ChatId
messageID = u.Message.Message.Id
isOutgoing = u.Message.Message.IsOutgoing
case *gotdbot.UpdateNewGuestQuery:
data, _ := json.MarshalIndent(update, "", " ")
if err := sendResult(c, u.Id, string(data)); err != nil {
c.Logger.Warnf("Failed to send JSON for guest query: %v", err)
}
return nil
}
if isOutgoing {
return nil
}
if chatID != 0 && !isDebugEnabled(chatID) {
return nil
}
data, marshalErr := json.MarshalIndent(update, "", " ")
if marshalErr != nil {
c.Logger.Debugf("Failed to marshal update: %v", marshalErr)
return nil
}
jsonStr := string(data)
if chatID == 0 {
c.Logger.Debugf("type=%s\n%s", update.GetType(), jsonStr)
return nil
}
if err := sendJSON(c, chatID, messageID, jsonStr); err != nil {
c.Logger.Warnf("Failed to send JSON: %v", err)
}
return nil
}