Skip to content

gldmtr/bot-golang

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VK Teams Bot API for Golang

Go codecov go.dev reference License: MIT

Getting started

  • 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 contact list, or if the user was the first to start a dialogue.

  • You can configure the domain that hosts your VK Teams server. When instantiating the Bot class, add the address of your domain.
  • An example of how to use the framework can be seen in example/main.go

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()

message.Text = "new text"

message.Edit()
message.Reply("I changed my text")

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 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://vkteams.com/bot/v1"))

And debug all api requests and responses:

bot := botgolang.NewBot(BOT_TOKEN, botgolang.BotDebug(true))

About

Golang library for Bot API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 99.3%
  • Makefile 0.7%