reactivetgbot

package module
v0.0.0-...-a87a67e Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2020 License: MIT Imports: 9 Imported by: 0

README

Development engine for Telegram ChatBot

Why do you need a ChatBot and why our team develop that tool?

Chatbots allow us to reduce the workload on staff by automating the processing of user requests. Therefore, it is necessary to create tools and libraries that accelerate the development. Useful case for providing ChatBot

Why should you use our solution?

Our solution allows you to forget about the code and directly engage in the creation of a processing environment Realization tips And you only just to need fill that table with question-answer pair. File with that pairs is using JSON format.

Example of question-answer pairs table

Provided in examplebase.json on this repository so now you can touch this with your own hands:)


[
    {
        "Question" : "/about",
        "Answer" : "ChatBot created by liquiddeath13 in 2019 year"
    },
    {
        "Question" : "Hello, how can i contact with your company?",
        "Answer" : "Hello, you can contact us by provided mail address. Email: coolnickname@hostname.domain"
    }
]

As you can see, filling out the question-answer pairs table is quite simple. It is also simple like making life easier for your employees who, on duty of a job, need a lot and often communicate with customers.

How-to use it inside Golang app

Firstly, you need to get that package with command:

go get "github.com/liquiddeath13/reactivetgbot"

And now you can use it at your application:

package main

import (
	reactivetgbot "github.com/liquiddeath13/reactivetgbot"
)

func main() {
    BotInstance := reactivetgbot.Init("token", "/path/base.json")
    if BotInstance != nil {
        go BotInstance.Logic()
        //if we need host our application on Heroku and shouldn't think about uptime
        reactivetgbot.HerokuServiceUP("Telegram ChatBot by liquiddeath13")
    }
}
Programmer-defined handler for commands handling support

Since new version, now you are able to specify some programm logic to handle incoming message data, but now you should return from that handle only string (interface type in next versions coming). Example:

package main

import (
	"fmt"
	reactivetgbot "github.com/liquiddeath13/reactivetgbot"
)

func main() {
	BotInstance := reactivetgbot.Init("token", "/path/base.json")
	AskCounter := 0
	if BotInstance != nil {
		BotInstance.AppendHandler("how much peoples asked you?", func(Msg reactivetgbot.TGMessage) string {
			AskCounter++
			return fmt.Sprintf("Hello.\n%d - so many people, who already asked me about this", AskCounter)
		})
		go BotInstance.Logic()
		reactivetgbot.HerokuServiceUP("Telegram ChatBot by liquiddeath13")
	}
}
Can you use it as standalone application?

It's impossible now, but in next versions it will be available to build application by cloning repo and just providing JSON file with question-answer pairs.

Where should you communicate with developer?

You can register an account on github (if you have not already done so) and leave a question or suggestion in the appropriate section of this repository. If you want to get in touch in another way, then there is also Gmail, Telegram, and Vkontakte.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Host = ""

Functions

func HandleInfoError

func HandleInfoError(arg interface{}, Error error) interface{}

func HandlePanicError

func HandlePanicError(arg interface{}, Error error) interface{}

Types

type Bot

type Bot struct {
	Unit      *tgbotapi.BotAPI
	Token     string
	LastError error
	QABase    map[string]interface{}
}

func Init

func Init(token, dictionary string) *Bot

func (*Bot) AppendPatternHandler

func (b *Bot) AppendPatternHandler(PatternList []string, Handler func(Msg TGMessage, args ...interface{}) string)

func (*Bot) HerokuUsage

func (b *Bot) HerokuUsage(Description string)

func (*Bot) Logic

func (b *Bot) Logic()

type QAPair

type QAPair struct {
	Question string `json:"Question"`
	Answer   string `json:"Answer"`
	Pattern  string `json:"Pattern"`
}

type TGMessage

type TGMessage *tgbotapi.Message

Jump to

Keyboard shortcuts

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