Use int64 for IDs, support captions
This commit is contained in:
parent
265938cdd7
commit
aa425600e3
6 changed files with 26 additions and 22 deletions
|
@ -55,12 +55,12 @@ func (t Telegram) SetWebhook(webhook string) {
|
|||
// SendTextMessage sends an HTML-styled text message to a specified chat
|
||||
func (t Telegram) SendTextMessage(data tg.ClientTextMessageData) {
|
||||
postdata := url.Values{
|
||||
"chat_id": {strconv.Itoa(data.ChatID)},
|
||||
"chat_id": {strconv.FormatInt(data.ChatID, 10)},
|
||||
"text": {data.Text},
|
||||
"parse_mode": {"HTML"},
|
||||
}
|
||||
if data.ReplyID != nil {
|
||||
postdata["reply_to_message_id"] = []string{strconv.Itoa(*(data.ReplyID))}
|
||||
postdata["reply_to_message_id"] = []string{strconv.FormatInt(*(data.ReplyID), 10)}
|
||||
}
|
||||
|
||||
_, err := http.PostForm(t.apiURL("sendMessage"), postdata)
|
||||
|
@ -86,10 +86,14 @@ func (t Telegram) SendPhoto(data tg.ClientPhotoData) {
|
|||
part.Write(photobytes[0:decoded])
|
||||
|
||||
// Write other fields
|
||||
writer.WriteField("chat_id", strconv.Itoa(data.ChatID))
|
||||
writer.WriteField("chat_id", strconv.FormatInt(data.ChatID, 10))
|
||||
|
||||
if data.ReplyID != nil {
|
||||
writer.WriteField("reply_to_message_id", strconv.Itoa(*data.ReplyID))
|
||||
writer.WriteField("reply_to_message_id", strconv.FormatInt(*data.ReplyID, 10))
|
||||
}
|
||||
|
||||
if data.Caption != "" {
|
||||
writer.WriteField("caption", data.Caption)
|
||||
}
|
||||
|
||||
err = writer.Close()
|
||||
|
|
|
@ -174,7 +174,7 @@ func memegen(broker *tg.Broker, update tg.APIMessage) {
|
|||
broker.SendTextMessage(update.Chat, "<b>ERRORE!</b> @hamcha controlla la console!", &update.MessageID)
|
||||
return
|
||||
}
|
||||
broker.SendPhoto(update.Chat, buf.Bytes(), "meme.jpg", nil, &update.MessageID)
|
||||
broker.SendPhoto(update.Chat, buf.Bytes(), "meme.jpg", "", &update.MessageID)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ func assert(err error) {
|
|||
}
|
||||
|
||||
var db *bolt.DB
|
||||
var chatID *int
|
||||
var chatID *int64
|
||||
|
||||
func process(broker *tg.Broker, update tg.APIMessage) {
|
||||
// Process messages from marked chat only
|
||||
|
@ -29,7 +29,7 @@ func main() {
|
|||
brokerAddr := flag.String("broker", "localhost:7314", "Broker address:port")
|
||||
webBind := flag.String("webserver", "localhost:7315", "Address to bind webserver to")
|
||||
boltdbFile := flag.String("boltdb", "stats.db", "BoltDB database file")
|
||||
chatID = flag.Int("chatid", -14625256, "Telegram Chat ID to count stats for")
|
||||
chatID = flag.Int64("chatid", -14625256, "Telegram Chat ID to count stats for")
|
||||
flag.Parse()
|
||||
|
||||
var err error
|
||||
|
|
16
tg/api.go
16
tg/api.go
|
@ -2,7 +2,7 @@ package tg
|
|||
|
||||
// APIUser represents the "User" JSON structure
|
||||
type APIUser struct {
|
||||
UserID int `json:"id"`
|
||||
UserID int64 `json:"id"`
|
||||
FirstName string `json:"first_name"`
|
||||
LastName string `json:"last_name,omitempty"`
|
||||
Username string `json:"username,omitempty"`
|
||||
|
@ -27,7 +27,7 @@ const (
|
|||
|
||||
// APIChat represents the "Chat" JSON structure
|
||||
type APIChat struct {
|
||||
ChatID int `json:"id"`
|
||||
ChatID int64 `json:"id"`
|
||||
Type ChatType `json:"type"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
Username *string `json:"username,omitempty"`
|
||||
|
@ -37,9 +37,9 @@ type APIChat struct {
|
|||
|
||||
// APIMessage represents the "Message" JSON structure
|
||||
type APIMessage struct {
|
||||
MessageID int `json:"message_id"`
|
||||
MessageID int64 `json:"message_id"`
|
||||
User APIUser `json:"from"`
|
||||
Time int `json:"date"`
|
||||
Time int64 `json:"date"`
|
||||
Chat *APIChat `json:"chat"`
|
||||
FwdUser *APIUpdate `json:"forward_from,omitempty"`
|
||||
FwdTime *int `json:"forward_date,omitempty"`
|
||||
|
@ -60,8 +60,8 @@ type APIMessage struct {
|
|||
GroupCreated *bool `json:"group_chat_created,omitempty"`
|
||||
SupergroupCreated *bool `json:"supergroup_chat_created,omitempty"`
|
||||
ChannelCreated *bool `json:"channel_chat_created,omitempty"`
|
||||
GroupToSuper *int `json:"migrate_to_chat_id,omitempty"`
|
||||
GroupFromSuper *int `json:"migrate_from_chat_id,omitempty"`
|
||||
GroupToSuper *int64 `json:"migrate_to_chat_id,omitempty"`
|
||||
GroupFromSuper *int64 `json:"migrate_from_chat_id,omitempty"`
|
||||
}
|
||||
|
||||
// APIPhotoSize represents the "PhotoSize" JSON structure
|
||||
|
@ -124,7 +124,7 @@ type APIContact struct {
|
|||
PhoneNumber string `json:"phone_number"`
|
||||
FirstName string `json:"first_name"`
|
||||
LastName *string `json:"last_name,omitempty"`
|
||||
UserID *int `json:"user_id,omitempty"`
|
||||
UserID *int64 `json:"user_id,omitempty"`
|
||||
}
|
||||
|
||||
// APILocation represents the "Location" JSON structure
|
||||
|
@ -135,7 +135,7 @@ type APILocation struct {
|
|||
|
||||
// APIUpdate represents the "Update" JSON structure
|
||||
type APIUpdate struct {
|
||||
UpdateID int `json:"update_id"`
|
||||
UpdateID int64 `json:"update_id"`
|
||||
Message APIMessage `json:"message"`
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ func (b *Broker) Close() {
|
|||
|
||||
// SendTextMessage sends a HTML-styles text message to a chat.
|
||||
// A reply_to message ID can be specified as optional parameter.
|
||||
func (b *Broker) SendTextMessage(chat *APIChat, text string, original *int) {
|
||||
func (b *Broker) SendTextMessage(chat *APIChat, text string, original *int64) {
|
||||
b.sendCmd(ClientCommand{
|
||||
Type: CmdSendTextMessage,
|
||||
TextMessageData: &ClientTextMessageData{
|
||||
|
@ -50,7 +50,7 @@ func (b *Broker) SendTextMessage(chat *APIChat, text string, original *int) {
|
|||
|
||||
// SendPhoto sends a photo with an optional caption to a chat.
|
||||
// A reply_to message ID can be specified as optional parameter.
|
||||
func (b *Broker) SendPhoto(chat *APIChat, data []byte, filename string, caption *string, original *int) {
|
||||
func (b *Broker) SendPhoto(chat *APIChat, data []byte, filename string, caption string, original *int64) {
|
||||
b.sendCmd(ClientCommand{
|
||||
Type: CmdSendPhoto,
|
||||
PhotoData: &ClientPhotoData{
|
||||
|
|
|
@ -39,18 +39,18 @@ const (
|
|||
|
||||
// ClientTextMessageData is the required data for a CmdSendTextMessage request
|
||||
type ClientTextMessageData struct {
|
||||
ChatID int
|
||||
ChatID int64
|
||||
Text string
|
||||
ReplyID *int `json:",omitempty"`
|
||||
ReplyID *int64 `json:",omitempty"`
|
||||
}
|
||||
|
||||
// ClientPhotoData is the required data for a CmdSendPhoto request
|
||||
type ClientPhotoData struct {
|
||||
ChatID int
|
||||
ChatID int64
|
||||
Bytes string
|
||||
Filename string
|
||||
Caption *string `json:",omitempty"`
|
||||
ReplyID *int `json:",omitempty"`
|
||||
Caption string `json:",omitempty"`
|
||||
ReplyID *int64 `json:",omitempty"`
|
||||
}
|
||||
|
||||
// FileRequestData is the required data for a CmdGetFile request
|
||||
|
|
Reference in a new issue