test
This commit is contained in:
parent
7e8dc69d6a
commit
c148d23aa9
4
def.go
4
def.go
@ -45,6 +45,10 @@ type MQKeepAlive struct {
|
|||||||
Date time.Time `json:"date"`
|
Date time.Time `json:"date"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CallbackMsgData struct {
|
||||||
|
Data `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
commandForwardMsg = 1
|
commandForwardMsg = 1
|
||||||
commandReplyMsg = 2
|
commandReplyMsg = 2
|
||||||
|
2
td.go
2
td.go
@ -300,7 +300,7 @@ func clientMsg(c *tdlib.Client, m TGCommand) {
|
|||||||
b, _ := json.Marshal(d)
|
b, _ := json.Marshal(d)
|
||||||
log.Printf("CallbackQueryPayloadData :\n%s\n", string(b))
|
log.Printf("CallbackQueryPayloadData :\n%s\n", string(b))
|
||||||
log.Printf("Type : %s\n", d.GetCallbackQueryPayloadEnum())
|
log.Printf("Type : %s\n", d.GetCallbackQueryPayloadEnum())
|
||||||
p, err := tdlib.unmarshalCallbackQueryPayload(b)
|
p, err := unmarshalCallbackQueryPayload(b)
|
||||||
|
|
||||||
a, err := c.GetCallbackQueryAnswer(m.FromChatID64, m.FromMsgID64, p)
|
a, err := c.GetCallbackQueryAnswer(m.FromChatID64, m.FromMsgID64, p)
|
||||||
logOnError(err, "clientMsg : GetCallbackQueryAnswer")
|
logOnError(err, "clientMsg : GetCallbackQueryAnswer")
|
||||||
|
30
utils.go
30
utils.go
@ -1,7 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
"github.com/Arman92/go-tdlib"
|
||||||
)
|
)
|
||||||
|
|
||||||
func failOnError(err error, msg string) {
|
func failOnError(err error, msg string) {
|
||||||
@ -15,3 +18,30 @@ func logOnError(err error, msg string) {
|
|||||||
log.Printf("%s: %s", msg, err)
|
log.Printf("%s: %s", msg, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func unmarshalCallbackQueryPayload(rawMsg *json.RawMessage) (tdlib.CallbackQueryPayload, error) {
|
||||||
|
|
||||||
|
if rawMsg == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
var objMap map[string]interface{}
|
||||||
|
err := json.Unmarshal(*rawMsg, &objMap)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch tdlib.CallbackQueryPayloadEnum(objMap["@type"].(string)) {
|
||||||
|
case tdlib.CallbackQueryPayloadDataType:
|
||||||
|
var callbackQueryPayloadData CallbackQueryPayloadData
|
||||||
|
err := json.Unmarshal(*rawMsg, &callbackQueryPayloadData)
|
||||||
|
return &callbackQueryPayloadData, err
|
||||||
|
|
||||||
|
case tdlib.CallbackQueryPayloadGameType:
|
||||||
|
var callbackQueryPayloadGame CallbackQueryPayloadGame
|
||||||
|
err := json.Unmarshal(*rawMsg, &callbackQueryPayloadGame)
|
||||||
|
return &callbackQueryPayloadGame, err
|
||||||
|
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("Error unmarshaling, unknown type:" + objMap["@type"].(string))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user