Phase 1 MVP — echo bot factory
All checks were successful
Docker Build / build-and-push-image (push) Successful in 1m8s
All checks were successful
Docker Build / build-and-push-image (push) Successful in 1m8s
This commit is contained in:
59
telegram_types.go
Normal file
59
telegram_types.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package main
|
||||
|
||||
type Update struct {
|
||||
UpdateID int64 `json:"update_id"`
|
||||
Message *Message `json:"message,omitempty"`
|
||||
EditedMessage *Message `json:"edited_message,omitempty"`
|
||||
CallbackQuery *CallbackQuery `json:"callback_query,omitempty"`
|
||||
}
|
||||
|
||||
type Message struct {
|
||||
MessageID int64 `json:"message_id"`
|
||||
From *User `json:"from,omitempty"`
|
||||
Chat Chat `json:"chat"`
|
||||
Date int64 `json:"date,omitempty"`
|
||||
Text string `json:"text,omitempty"`
|
||||
}
|
||||
|
||||
type Chat struct {
|
||||
ID int64 `json:"id"`
|
||||
Type string `json:"type,omitempty"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID int64 `json:"id"`
|
||||
IsBot bool `json:"is_bot,omitempty"`
|
||||
Username string `json:"username,omitempty"`
|
||||
FirstName string `json:"first_name,omitempty"`
|
||||
}
|
||||
|
||||
type CallbackQuery struct {
|
||||
ID string `json:"id"`
|
||||
From *User `json:"from,omitempty"`
|
||||
Message *Message `json:"message,omitempty"`
|
||||
Data string `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
func (u Update) ChatID() (int64, bool) {
|
||||
switch {
|
||||
case u.Message != nil:
|
||||
return u.Message.Chat.ID, true
|
||||
case u.EditedMessage != nil:
|
||||
return u.EditedMessage.Chat.ID, true
|
||||
case u.CallbackQuery != nil && u.CallbackQuery.Message != nil:
|
||||
return u.CallbackQuery.Message.Chat.ID, true
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
|
||||
func (u Update) Text() string {
|
||||
switch {
|
||||
case u.Message != nil:
|
||||
return u.Message.Text
|
||||
case u.EditedMessage != nil:
|
||||
return u.EditedMessage.Text
|
||||
case u.CallbackQuery != nil:
|
||||
return u.CallbackQuery.Data
|
||||
}
|
||||
return ""
|
||||
}
|
||||
Reference in New Issue
Block a user