Engine for creating chatbots for Utopia Messenger
You don't want to understand Utopia API, but you have an idea how to make a bot that works with users in private and public messages.
The engine can:
- process messages from contacts;
- process messages in channels (private & public messages);
- automatically logs into channels, can use the password for closed channels.
- Chatbots that raise and retain user activity in channels.
- Bots for performing services to users.
- Creating a bot constructor.
go get github.com/Sagleft/uchatbot-engine
package main
import (
"fmt"
"log"
"github.com/Sagleft/uchatbot-engine"
utopiago "github.com/Sagleft/utopialib-go/v2"
"github.com/Sagleft/utopialib-go/v2/pkg/structs"
"github.com/fatih/color"
)
const APIToken = "your-utopia-api-token"
func main() {
bot, err := uchatbot.NewChatBot(uchatbot.ChatBotData{
Config: utopiago.Config{
Host: "127.0.0.1",
Token: APIToken,
Port: 20000,
WsPort: 25000,
},
Chats: []uchatbot.Chat{
{ID: "D53B4431FD604E2F0261792444797AA4"},
{ID: "A59D8B62E1A59049564A4B0F8B457D45"},
},
Callbacks: uchatbot.ChatBotCallbacks{
OnContactMessage: OnContactMessage,
OnChannelMessage: OnChannelMessage,
OnPrivateChannelMessage: OnPrivateChannelMessage,
WelcomeMessage: OnWelcomeMessage,
},
UseErrorCallback: true,
ErrorCallback: onError,
})
if err != nil {
log.Fatalln(err)
}
log.Println("bot started")
bot.Wait()
}
func OnContactMessage(m structs.InstantMessage) {
fmt.Printf("[CONTACT] %s: %s\n", m.Nick, m.Text)
}
func OnChannelMessage(m structs.WsChannelMessage) {
fmt.Printf("[CHANNEL] %s: %s\n", m.Nick, m.Text)
}
func OnPrivateChannelMessage(m structs.WsChannelMessage) {
fmt.Printf("[PRIVATE] %s: %s\n", m.Nick, m.Text)
}
func OnWelcomeMessage(userPubkey string) string {
return fmt.Sprintf("Hello! Your pubkey is %s", userPubkey)
}
func onError(err error) {
color.Red(err.Error())
}
You can find me in Utopia: F50AF5410B1F3F4297043F0E046F205BCBAA76BEC70E936EB0F3AB94BF316804