bot

package
v0.0.0-...-71ac371 Latest Latest
Warning

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

Go to latest
Published: May 13, 2021 License: MIT Imports: 17 Imported by: 0

README

telegram bot

bot screens

                       (*)
                        │
                        ▼
╔════════════════════════════════════════════════╗
║ WelcomeScreen                                  ║
╟────────────────────────────────────────────────╢
║ Welcome!                                       ║
║ This is a WAQI bot                             ║
║                                                ║
║ Send a location to get its current air quality ║
╟────────────────────────────────────────────────╢
║ [Send location]                                ║
╚════════════════════════════════════════════════╝
              │                 ▲            ▲
              │ ─── @location   │            │
              │                 │ ─── /back  │
              ▼                 │            │
   ╔═════════════════════════════════════╗   │
   ║ LocationScreen                      ║   │
   ╟─────────────────────────────────────╢   │
   ║ %LocationName%                      ║   │
   ║ Current air quaility: Good          ║   │
   ║ CO_2: %CO2%                         ║   │
   ╟─────────────────────────────────────╢   │
   ║ [Subscribe to this location]        ║   │
   ╚═════════════════════════════════════╝   │
            │                                │
            │ ─── /subscribe                 │
            │                                │ ─── /unsubscribe
            ▼                                │
   ╔════════════════════════════════════════════════════════════╗
   ║ SubscribedScreen                                           ║
   ╟────────────────────────────────────────────────────────────╢
   ║ Subscribed to %LocationName%                               ║
   ║ You will receive notification if air quaility here changes ║
   ╟────────────────────────────────────────────────────────────╢
   ║ [Unsubscribe]                                              ║
   ╚════════════════════════════════════════════════════════════╝

Documentation

Index

Constants

View Source
const (
	StateNotSubscribed = "not_subscribed"
	StateSubscribed    = "subscribed"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot interface {
	// Start starts Bot
	Start() error

	// Close shuts down Bot
	Close()
}

Bot wraps Bot logic

func NewBot

func NewBot(fn ...Option) (Bot, error)

NewBot creates an instance of Bot

type DB

type DB interface {
	// GetOrCreate fetches a chat state from DB
	// If chat is not registered yet, it will be created
	GetOrCreate(chatID int64, userID int, username string) (*chatEntity, error)

	// Update stores chat state into DB
	Update(chat *chatEntity) error

	// GetSubscribedStationIDs returns map of stations with subscription
	// Map key is station ID and value is count of active subscriptions
	GetSubscribedStationIDs() (map[int]int, error)

	// GetSubscribedChats returns map of chats subscribed to specified station
	GetSubscribedChats(stationID int) ([]*chatEntity, error)

	// Close shuts down DB
	Close()
}

func NewDB

func NewDB(filepath string, logger *log.Logger) (DB, error)

NewDB creates new instance of DB

type Option

type Option func(*options)

Option is a configuration option for NewBot function

func AllowedUsernamesOption

func AllowedUsernamesOption(allowedUsernames []string) Option

AllowedUsernamesOption sets list of allowed usernames

func DBPathOption

func DBPathOption(path string) Option

DBPathOption sets path to DB file

func LoggerOption

func LoggerOption(logger *log.Logger) Option

LoggerOption sets logger instance

func TokenOption

func TokenOption(token string) Option

TokenOption sets Telegram access token

func URLOption

func URLOption(url string) Option

URLOption sets Telegram BotAPI URL

func WAQIServiceOption

func WAQIServiceOption(waqiService waqi.Service) Option

WAQIServiceOption sets WAQI service instance

Jump to

Keyboard shortcuts

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