func (h *Handler) rateInline(ctrl *telegram.Control, bot *tgbotapi.BotAPI, update tgbotapi.Update, call slugger.Call) { if len(call.Query) != 2 { ctrl.Throw(ErrRateExpectTwoArguments) return } if err := validateCurrency(call.Query[0]); err != nil { ctrl.Throw(err) return } if err := validateCurrency(call.Query[1]); err != nil { ctrl.Throw(err) return } from, to := toCurrency(call.Query[0]), toCurrency(call.Query[1]) rate, err := h.f.GetRate(ctrl.Context(), from, to) if err != nil { ctrl.Throw(err) return } bot.AnswerInlineQuery(tgbotapi.InlineConfig{ InlineQueryID: update.InlineQuery.ID, Results: []interface{}{ inlineResultArticle(from, to, rate.Rate), }, }) ctrl.Next() }
func (self Condition) Serve(ctrl *telegram.Control, bot *tgbotapi.BotAPI, update tgbotapi.Update) { if self.Matcher.Match(update) { self.Handler.Serve(ctrl, bot, update) return } ctrl.Next() }
func (r *Slugger) Serve(ctrl *telegram.Control, bot *tgbotapi.BotAPI, update tgbotapi.Update) { var call Call text := strings.TrimPrefix(update.Message.Text, methodPrefix) fill(&call.Args, text) fill(&call.Query, update.InlineQuery.Query) ctrl.NextWithValue(reflect.TypeOf(call), call) ctrl.Next() }
func (h *Handler) rouble(ctrl *telegram.Control, bot *tgbotapi.BotAPI, update tgbotapi.Update, call slugger.Call) { if len(call.Args) != 1 { ctrl.Throw(ErrRoubleExpectOneArgument) return } if err := validateCurrency(call.Args[0]); err != nil { ctrl.Throw(err) return } rate, err := h.f.GetRate(ctrl.Context(), toCurrency(call.Args[0]), finance.RUB) if err != nil { ctrl.Throw(err) return } bot.Send(tgbotapi.NewMessage(update.Message.Chat.ID, strconv.FormatFloat(rate.Rate, 'f', 2, 64))) ctrl.Next() }
func (h *Handler) Serve(ctrl *telegram.Control, bot *tgbotapi.BotAPI, update tgbotapi.Update) { msg := tgbotapi.NewMessage(update.Message.Chat.ID, help.HelpContents) msg.ParseMode = telegram.ParseModeMarkdown bot.Send(msg) ctrl.Next() }
func (c *Canceler) Serve(ctrl *telegram.Control, bot *tgbotapi.BotAPI, update tgbotapi.Update) { ctrl.NextWithTimeout(c.Timeout) ctrl.Next() }