Documentation ¶
Index ¶
- Constants
- Variables
- func GetKey(ctx context.Context, i int64) *datastore.Key
- func GetTopStoryURL() string
- func ItemURL(id int64) string
- func NewsURL(id int64) string
- func TelegramAPI(method string) string
- type DeleteMessageRequest
- type DeleteMessageResponse
- type EditMessageTextRequest
- type InlineKeyboardButton
- type InlineKeyboardMarkup
- type IntSet
- type Result
- type SendMessageRequest
- type SendMessageResponse
- type Story
- func (s *Story) DeleteMessage(ctx context.Context) error
- func (s *Story) EditMessage(ctx context.Context) error
- func (s *Story) FillMissingFields(ctx context.Context) error
- func (s *Story) GetReplyMarkup() InlineKeyboardMarkup
- func (s *Story) InDatastore(ctx context.Context) bool
- func (s *Story) Load(ps []datastore.Property) error
- func (s *Story) Save() ([]datastore.Property, error)
- func (s *Story) SendMessage(ctx context.Context) error
- func (s *Story) ShouldIgnore() bool
- func (s *Story) ToDeleteMessageRequest() DeleteMessageRequest
- func (s *Story) ToEditMessageTextRequest() EditMessageTextRequest
- func (s *Story) ToSendMessageRequest() SendMessageRequest
Constants ¶
const BatchSize = 30
BatchSize is the number of top stories to fetch from Hacker News.
const DefaultChatID = `@yahnc`
DefaultChatID is the default chat ID.
const DefaultTimeout = 9 * time.Minute
DefaultTimeout is the default URLFetch timeout.
const Hot = "🔥"
Hot is the sign for a hot story, either because it has high score or it has large number of discussions.
const NumCommentsThreshold = 5
NumCommentsThreshold is the threshold for number of comments. Story with less than this threshold will not be posted in the channel.
const ScoreThreshold = 50
ScoreThreshold is the threshold for the score. Story with less than this threshold will not be posted in the channel.
const TelegramAPIBase = `https://api.telegram.org/`
TelegramAPIBase is the API base of telegram API.
Variables ¶
var ErrIgnoredItem = errors.New("item ignored")
ErrIgnoredItem is returned when the story should be ignored.
Functions ¶
func TelegramAPI ¶
TelegramAPI is a helper function to get the Telegram API endpoint.
Types ¶
type DeleteMessageRequest ¶
type DeleteMessageRequest struct { ChatID string `json:"chat_id"` MessageID int64 `json:"message_id"` }
DeleteMessageRequest is the request to deleteMessage method.
type DeleteMessageResponse ¶
type DeleteMessageResponse struct { OK bool `json:"ok"` ErrorCode int64 `json:"error_code"` Description string `json:"description"` }
DeleteMessageResponse is the response to deleteMessage method.
func (*DeleteMessageResponse) ShouldIgnoreError ¶
func (r *DeleteMessageResponse) ShouldIgnoreError() bool
ShouldIgnoreError return true if the message contains an error but should be ignored.
type EditMessageTextRequest ¶
type EditMessageTextRequest struct { ChatID string `json:"chat_id"` MessageID int64 `json:"message_id"` Text string `json:"text"` ParseMode string `json:"parse_mode,omitempty"` ReplyMarkup InlineKeyboardMarkup `json:"reply_markup,omitempty"` }
EditMessageTextRequest is the request to editMessageText method.
type InlineKeyboardButton ¶
type InlineKeyboardButton struct { Text string `json:"text,omitempty"` URL string `json:"url,omitempty"` }
InlineKeyboardButton type.
type InlineKeyboardMarkup ¶
type InlineKeyboardMarkup struct {
InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard,omitempty"`
}
InlineKeyboardMarkup type.
type IntSet ¶
type IntSet map[int64]struct{}
IntSet is an int64 set type.
type Result ¶
type Result struct {
MessageID int64 `json:"message_id"`
}
Result is a submessage in SendMessageResponse. We only care the MessageID for now.
type SendMessageRequest ¶
type SendMessageRequest struct { ChatID string `json:"chat_id"` Text string `json:"text"` ParseMode string `json:"parse_mode,omitempty"` ReplyMarkup InlineKeyboardMarkup `json:"reply_markup,omitempty"` DisableNotification bool `json:"disable_notification,omitempty"` }
SendMessageRequest is a struct that maps to a sendMessage request.
type SendMessageResponse ¶
SendMessageResponse is the response from sendMessage request.
type Story ¶
type Story struct { ID int64 `json:"id"` URL string `json:"url"` Title string `json:"title"` Descendants int64 `json:"descendants"` Score int64 `json:"score"` MessageID int64 `json:"-"` LastSave time.Time `json:"-"` Type string `json:"type"` // contains filtered or unexported fields }
Story is a struct represents an item stored in datastore. Part of the fields will be saved to datastore.
func NewFromDatastore ¶
NewFromDatastore create a Story from datastore.
func (*Story) DeleteMessage ¶
DeleteMessage delete a message from telegram Channel and from channel.
func (*Story) EditMessage ¶
EditMessage send a request to edit a message.
func (*Story) FillMissingFields ¶
FillMissingFields is used to fill the missing story data from HN API.
func (*Story) GetReplyMarkup ¶
func (s *Story) GetReplyMarkup() InlineKeyboardMarkup
GetReplyMarkup will return the markup for the story.
func (*Story) InDatastore ¶
InDatastore checks if the story is already in datastore.
func (*Story) SendMessage ¶
SendMessage send a request to send a new message.
func (*Story) ShouldIgnore ¶
ShouldIgnore is a filter for story.
func (*Story) ToDeleteMessageRequest ¶
func (s *Story) ToDeleteMessageRequest() DeleteMessageRequest
ToDeleteMessageRequest returns a DeleteMessageRequest.
func (*Story) ToEditMessageTextRequest ¶
func (s *Story) ToEditMessageTextRequest() EditMessageTextRequest
ToEditMessageTextRequest will return a new EditMessageTextRequest object
func (*Story) ToSendMessageRequest ¶
func (s *Story) ToSendMessageRequest() SendMessageRequest
ToSendMessageRequest will return a new SendMessageRequest object