Bot Golang Save Abandoned

Golang library for Bot API

Project README

Golang interface for Mail.ru Instant Messengers bot API

License: MIT CircleCI go.dev reference

  • Brand new Bot API!

  • Zero-configuration library

  • Simple and clear interface

API specification:

ICQ New

Myteam

Agent Mail.ru

Install

go get github.com/mail-ru-im/bot-golang

Usage

Create your own bot by sending the /newbot command to Metabot and follow the instructions.

Note a bot can only reply after the user has added it to his contacts list, or if the user was the first to start a dialogue.

Create your bot

package main

import "github.com/mail-ru-im/bot-golang"

func main() {
    bot, err := botgolang.NewBot(BOT_TOKEN)
    if err != nil {
        log.Println("wrong token")
    }

    message := bot.NewTextMessage("[email protected]", "text")
    message.Send()
}

Send and edit messages

You can create, edit and reply to messages like a piece of cake.

message := bot.NewTextMessage("[email protected]", "text")
message.Send()

fmt.Println(message.MsgID)

message.Text = "new text"

message.Edit()
// AWESOME!

message.Reply("hey, what did you write before???")
// SO HOT!

Subscribe events

Get all updates from the channel. Use context for cancellation.

ctx, finish := context.WithCancel(context.Background())
updates := bot.GetUpdatesChannel(ctx)
for update := range updates {
	// your awesome logic here
}

Passing options

You don't need this. But if you do, you can override bot's API URL:

bot := botgolang.NewBot(BOT_TOKEN, botgolang.BotApiURL("https://agent.mail.ru/bot/v1"))

And debug all api requests and responses:

bot := botgolang.NewBot(BOT_TOKEN, botgolang.BotDebug(true))
Open Source Agenda is not affiliated with "Bot Golang" Project. README Source: mail-ru-im/bot-golang
Stars
53
Open Issues
5
Last Commit
1 year ago
License
MIT

Open Source Agenda Badge

Open Source Agenda Rating