telegrambot

package
v0.2.0-beta.13.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2018 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Copyright © 2018 BigOokie

Use of this source code is governed by an MIT license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateMarkup

func CreateMarkup(btns ...string) tgbotapi.InlineKeyboardMarkup

CreateMarkup will return a tgbotapi.InlineKeyboardMarkup. Supports a single button row only

func CreateMultiLineMarkup

func CreateMultiLineMarkup(btns ...string) tgbotapi.InlineKeyboardMarkup

CreateMultiLineMarkup will build and return a multiline tgbotapi.InlineKeyboardMarkup The "|" character is used in the btns input to define the end of a row for example "1", "2", "|", "3", "4" will produce two rows with "1", "2" and "3", "4"

Types

type Bot

type Bot struct {
	// contains filtered or unexported fields
}

Bot provides management of the interface to the Telegram Bot

func NewBot

func NewBot(config wcconfig.Config) (*Bot, error)

NewBot will create a new instance of a Bot struct based on the passed Config structure which supplies runtime configuration for the bot.

func (*Bot) AddGroupMessageHandler

func (bot *Bot) AddGroupMessageHandler(handler MessageHandler)

AddGroupMessageHandler adds a group MessageHandler to the Bot

func (*Bot) AddPrivateMessageHandler

func (bot *Bot) AddPrivateMessageHandler(handler MessageHandler)

AddPrivateMessageHandler adds a private MessageHandler to the Bot

func (*Bot) Reply

func (bot *Bot) Reply(ctx *BotContext, format, text string) error

Reply will respond to a message received by the Bot in the BotContext (ctx). Specify the reply format and message text as parameters.

func (*Bot) Send

func (bot *Bot) Send(ctx *BotContext, mode, format, text string) error

Send will send a new message from the Bot using the provided BotContext The mode, format and text parameters are used to constuct the message and determine its format and delivery

func (*Bot) SendGAEvent

func (bot *Bot) SendGAEvent(category, action, label string)

SendGAEvent will send a GA Event on the

func (*Bot) SendMainMenuMessage

func (bot *Bot) SendMainMenuMessage(ctx *BotContext) error

SendMainMenuMessage will send a main menu message

func (*Bot) SendNewMessage

func (bot *Bot) SendNewMessage(format, text string) error

SendNewMessage will send a new message without requiring a BotContext.

func (*Bot) SendReplyInlineKeyboard

func (bot *Bot) SendReplyInlineKeyboard(ctx *BotContext, kb tgbotapi.InlineKeyboardMarkup, text string) error

SendReplyInlineKeyboard will send a reply using the provided inline keyboard

func (*Bot) Start

func (bot *Bot) Start()

Start will start the Bot running - the main duty being to monitor for and handle messages

type BotContext

type BotContext struct {
	User *User
	// contains filtered or unexported fields
}

BotContext provides context for Bot Messages

func (*BotContext) IsCallBackQuery

func (ctx *BotContext) IsCallBackQuery() bool

IsCallBackQuery will evaluate the BotContext and determine if it is a CallBackQueyr or not

func (*BotContext) IsUserMessage

func (ctx *BotContext) IsUserMessage() bool

IsUserMessage will evaluate the BotContext and determine if it is a regular User Message or not

type Command

type Command struct {
	Admin       bool
	Command     string
	Handlerfunc CommandHandler
}

Command struct is used to define a Telegram Bot command, including if its an Admin only command, the string command (i.e. `/start`) and the function that will handle the command

type CommandHandler

type CommandHandler func(*Bot, *BotContext, string, string) error

CommandHandler provides an interface specification for command handlers

type Commands

type Commands []Command

Commands provides an array (slice) of Command structs

type MessageHandler

type MessageHandler func(*Bot, *BotContext, string) (bool, error)

MessageHandler provides an interface specification for message handlers

type User

type User struct {
	ID        int    `json:"id"`
	UserName  string `db:"username" json:"username,omitempty"`
	FirstName string `db:"first_name" json:"first_name,omitempty"`
	LastName  string `db:"last_name" json:"last_name,omitempty"`
	Banned    bool   `json:"banned"`
	Admin     bool   `json:"admin"`
}

User is a structure to model the Telegram Bot user that is being interacted with

func (*User) NameAndTags

func (u *User) NameAndTags() string

NameAndTags is a helper function to append namess and tags to users within the group

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL