commons

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LibName    = "xapp-chatbot"
	LibVersion = "0.1.1"

	DbName   = "chatbot"
	DbDriver = "sqlite"
	DbFile   = "chatbot.db"

	ChatbotSettingsFilepattern   = "chatbot.%s.json"
	ExternalsSettingsFilepattern = "externals.%s.json"
)
View Source
const (
	DriverChatGPT  = "chatgpt"
	DriverDALLE    = "dalle"
	DriverUnsplash = "unsplash"

	DriverWordpress = "wordpress"
)
View Source
const (
	EventOnIncomingMessage = "on_incoming_message"
	EventOnOutgoingMessage = "on_outgoing_message"
)
View Source
const (
	EventOnScheduled        = "on_scheduler_new"  // emitted from scheduler
	EventOnArticleToPublish = "on_copywriter_new" // emitted from copywriter
	EventOnArticlePublished = "on_publisher_new"  // emitted from publisher
)
View Source
const (
	DriverTelegram = "telegram"
)

Variables

View Source
var (
	ErrorDriverNotSupported = errors.New("driver_not_supported")
	ErrorMissingToken       = errors.New("missing_token")
	ErrorMissingConnection  = errors.New("missing_connection")
)
View Source
var (
	BotoloDbCryptoKey = ""
)

Functions

func Decrypt

func Decrypt(value string) (response string)

func DetectLanguage

func DetectLanguage(text string) (langCode string)

func Download

func Download(url string) (data []byte, err error)

func Encrypt

func Encrypt(value string) string

func GetChatUserUID

func GetChatUserUID(driver, userId string) (uid string)

func GetChatbotRoot

func GetChatbotRoot(botUID string) string

func GetFilenameChatbotSettings

func GetFilenameChatbotSettings(mode string) string

func GetFilenameSettings

func GetFilenameSettings(pattern, mode string) string

func Hashtags

func Hashtags(keywords []string) string

func IsQuoted

func IsQuoted(text string) bool

func MD5

func MD5(value string) string

func Quote

func Quote(text string) string

func RemoveFromString

func RemoveFromString(text string, cut []string, n int) string

func SplitKeywords

func SplitKeywords(text string) (response []string)

func SplitRows

func SplitRows(text string) (response []string)

func SummarizeText

func SummarizeText(text string, numSentences int) (response string, err error)

func SummarizeTextFile

func SummarizeTextFile(filename string, numSentences int) (response string, err error)

func ToArrayOfMap

func ToArrayOfMap(value interface{}) (response []map[string]interface{}, err error)

func ToMap

func ToMap(value interface{}) (response map[string]interface{}, err error)

func Trim

func Trim(text string) string

func Unquote

func Unquote(text string) string

func WriteFile

func WriteFile(filename, content string) (err error)

Types

type BotMessage

type BotMessage struct {
	UserID           uint   // internal user id
	UserLang         string // internal user lang
	Driver           string
	FromID           string
	MessageID        string
	ReplyToMessageID string // set only if a replyTo is required
	ChatID           string // id of the chat where message live
	Text             string
	Date             time.Time
}

func (*BotMessage) CreateReplyTo

func (instance *BotMessage) CreateReplyTo() *BotMessage

func (*BotMessage) CreateResponse

func (instance *BotMessage) CreateResponse() *BotMessage

type IBot

type IBot interface {
	Uid() string
	Name() string
	String() string
	Start() (err error)
	Stop() (err error)
	IsDebug() bool

	ClearHandlers()
	SetHandlers(handlers []MessageHandler)
	AddHandler(handler MessageHandler)
}

type IPublisher

type IPublisher interface {
	GetUid() string
	IsEnabled() bool
	Publish(item interface{}) error
}

type Keyword

type Keyword struct {
	Weight int
	Value  string
}

func Keywords

func Keywords(text string, minLen, minWeight, maxCount int, sortByWeight bool) (response []*Keyword)

func (*Keyword) String

func (instance *Keyword) String() string

type MessageHandler

type MessageHandler func(bot IBot, message *BotMessage) (handled bool, response *BotMessage)

type SettingsBot

type SettingsBot struct {
	Bots      []*SettingsBotInfo  `json:"bots"`
	Externals []*SettingsExternal `json:"externals"`
}

func (*SettingsBot) HasExternal

func (instance *SettingsBot) HasExternal(uid string) (response bool, item *SettingsExternal)

func (*SettingsBot) Map

func (instance *SettingsBot) Map() map[string]interface{}

func (*SettingsBot) String

func (instance *SettingsBot) String() string

type SettingsBotInfo

type SettingsBotInfo struct {
	Uid       string              `json:"uid"`
	DbDriver  string              `json:"db-driver"`
	DbDsn     string              `json:"db-dsn"`
	Driver    string              `json:"driver"`
	Name      string              `json:"name"`
	Username  string              `json:"username"`
	Token     string              `json:"token"`
	Fallback  string              `json:"fallback"` // file or external
	Externals []*SettingsExternal `json:"externals"`
}

SettingsBotInfo

{
  "bots": [
    {
      "uid": "telegram-botolo",
      "driver": "telegram",
      "name": "botolo",
      "username": "mybotolo_bot",
      "token": "-"
    }
  ]
}

func (*SettingsBotInfo) GetDbDsn

func (instance *SettingsBotInfo) GetDbDsn() string

func (*SettingsBotInfo) HasExternal

func (instance *SettingsBotInfo) HasExternal(uid string) (response bool, item *SettingsExternal)

type SettingsExternal

type SettingsExternal struct {
	Uid      string                 `json:"uid"`
	Driver   string                 `json:"driver"`
	User     string                 `json:"user"`
	Password string                 `json:"password"`
	Token    string                 `json:"token"`
	Payload  map[string]interface{} `json:"payload"`
}
	{
      "uid": "openai_chatgpt",
      "driver": "chatgpt",
      "user": "",
      "password": "",
      "token": "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"
    }

Jump to

Keyboard shortcuts

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