VK bot package for Go

Go VK bot package

Build Status codecov Go Report Card godoc

This is simple VK.com bot API.

At 2019-03-01 VK was restrict messages.send for user_tokens. This bot can work with group_token, and access to chat members if has admin rights in chat. You can use v1.0.1 also, if you need only user_token access.

It can:

  • Reply to messages (private and chat)
  • Send greetings message when invited to chat
  • Add and remove mutual friends
  • Send notifies to admin

Installatioin:

Use go mod For old Go versions you can also use go get github.com/nikepan/govkbot/v2

For work you need get VK access token with rights: messages,friends,offline (see below).

Quickstart

package main
import "github.com/nikepan/govkbot/v2"
import "log"

var VKAdminID = 3759927
var VKToken = "efjr98j9fj8jf4j958jj4985jfj9joijerf0fj548jf94jfiroefije495jf48"

func helpHandler(m *govkbot.Message) (reply string) {
  return "help received"
}

func startHandler(m *govkbot.Message) (reply govkbot.Reply) {
	keyboard := govkbot.Keyboard{Buttons: make([][]govkbot.Button, 0)}
	button := govkbot.NewButton("/help", nil)
	row := make([]govkbot.Button, 0)
	row = append(row, button)
	keyboard.Buttons = append(keyboard.Buttons, row)

	return govkbot.Reply{Msg: availableCommands, Keyboard: &keyboard}
}

func errorHandler(m *govkbot.Message, err error) {
  log.Fatal(err.Error())
}

func main() {
    //govkbot.HandleMessage("/", anyHandler)
    //govkbot.HandleMessage("/me", meHandler)
    govkbot.HandleMessage("/help", helpHandler)
    govkbot.HandleAdvancedMessage("/start", startHandler)

    //govkbot.HandleAction("chat_invite_user", inviteHandler)
    //govkbot.HandleAction("chat_kick_user", kickHandler)
    //govkbot.HandleAction("friend_add", addFriendHandler)
    //govkbot.HandleAction("friend_delete", deleteFriendHandler)

    govkbot.HandleError(errorHandler)

    govkbot.SetAutoFriend(true) // enable auto accept/delete friends

    govkbot.SetDebug(true) // log debug messages

    // Optional Direct VK API access
    govkbot.SetAPI(VKToken, "", "") // Need only before Listen, if you use direct API
    me, _ := govkbot.API.Me() // call API method
    log.Printf("current user: %+v\n", me.FullName())
    // Optional end

    govkbot.Listen(VKToken, "", "", VKAdminID)
}

Getting group token

Open group manage and select "Work with API"

Getting user token (most likely will not work for messages)

You need standalone vk app_id. You can use any app_id from https://vk.com/apps?act=wingames, for example 4775211 (Or you can create own app and get app_id on page https://vk.com/editapp?act=create (standalone app))

You can get token from you server ip with this node.js package: https://www.npmjs.com/package/vk-auth (you need login, pass and app_id)

To manual get token you need:

  1. Open in browser with logged in VK (you must use IP, where you want run bot)
 https://oauth.vk.com/authorize?client_id={{app_id}}&scope=offline,groups,messages,friends&display=page&response_type=token&redirect_uri=https://oauth.vk.com/blank.html
  1. Copy token query parameter from URL string. Token valid only for IP from what you get it.

If you receive validation check (for example, you use ip first time)

{"error":{"error_code":17,"error_msg":"Validation required: please open redirect_uri in browser ...", 
"redirect_uri":"https://m.vk.com/login?act=security_check&api_hash=Qwerty1234567890"}}

you can use https://github.com/Yashko/vk-validation-node.

Owner
Similar Resources

IRC, Slack, Telegram and RocketChat bot written in go

IRC, Slack, Telegram and RocketChat bot written in go

go-bot IRC, Slack & Telegram bot written in Go using go-ircevent for IRC connectivity, nlopes/slack for Slack and Syfaro/telegram-bot-api for Telegram

Dec 20, 2022

Simple yet customizable bot framework written in Go.

Simple yet customizable bot framework written in Go.

Introduction Sarah is a general-purpose bot framework named after the author's firstborn daughter. This comes with a unique feature called "stateful c

Dec 12, 2022

Golang telegram bot API wrapper, session-based router and middleware

go-tgbot Pure Golang telegram bot API wrapper generated from swagger definition, session-based routing and middlewares. Usage benefits No need to lear

Nov 16, 2022

A golang implementation of a console-based trading bot for cryptocurrency exchanges

A golang implementation of a console-based trading bot for cryptocurrency exchanges

Golang Crypto Trading Bot A golang implementation of a console-based trading bot for cryptocurrency exchanges. Usage Download a release or directly bu

Dec 30, 2022

Kelp is a free and open-source trading bot for the Stellar DEX and 100+ centralized exchanges

Kelp is a free and open-source trading bot for the Stellar DEX and 100+ centralized exchanges

Kelp Kelp is a free and open-source trading bot for the Stellar universal marketplace and for centralized exchanges such as Binance, Kraken, CoinbaseP

Jan 6, 2023

Telegram Bot Framework for Go

Margelet Telegram Bot Framework for Go is based on telegram-bot-api It uses Redis to store it's states, configs and so on. Any low-level interactions

Dec 22, 2022

Client lib for Telegram bot api

Micha Client lib for Telegram bot api. Supports Bot API v2.3.1 (of 4th Dec 2016). Simple echo bot example: package main import ( "log" "git

Nov 10, 2022

Slack Bot Framework

slacker Built on top of the Slack API github.com/slack-go/slack with the idea to simplify the Real-Time Messaging feature to easily create Slack Bots,

Dec 25, 2022

Slack bot core/framework written in Go with support for reactions to message updates/deletes

Slack bot core/framework written in Go with support for reactions to message updates/deletes

Overview Requirements Features Demo The Name Concepts Create Your Own Slackscot Assembling the Parts and Bringing Your slackscot to Life Configuration

Oct 28, 2022
Dlercloud-telegram-bot - A Telegram bot for managing your Dler Cloud account

Dler Cloud Telegram Bot A Telegram bot for managing your Dler Cloud account. Usa

Dec 30, 2021
Quote-bot - Un bot utilisant l'API Twitter pour tweeter une citation par jour sur la programmation et les mathématiques.

Description Ceci est un simple bot programmé en Golang qui tweet une citation sur la programmation tout les jours. Ce bot est host sur le compte Twitt

Jan 1, 2022
Discord-bot - A Discord bot with golang

JS discord bots Install Clone repo git clone https://github.com/fu-js/discord-bo

Aug 2, 2022
Bot - Telegram Music Bot in Go

Telegram Music Bot in Go An example bot using gotgcalls. Setup Install the serve

Jun 28, 2022
Pro-bot - A telegram bot to play around with the community telegram channels

pro-bot ?? Pro Bot A Telegram Bot to Play Around With The Community Telegram Cha

Jan 24, 2022
Slack-emoji-bot - This Slack bot will post the newly created custom Slack emojis to the channel of your choice

Slack Emoji Bot This Slack bot will post the newly created custom Slack emojis t

Oct 21, 2022
Sex-bot - The sex bot and its uncreative responses
Sex-bot - The sex bot and its uncreative responses

Sex Bot The sex bot, made with golang! The sex bot can't hear the word "sexo" he

Nov 11, 2022
Feline-bot - Feline Bot for Discord using Golang

Feline Bot for Discord Development This bot is implemented using Golang. Feature

Feb 10, 2022
VK bot package for Go

Go VK bot package This is simple VK.com bot API. At 2019-03-01 VK was restrict messages.send for user_tokens. This bot can work with group_token, and

Sep 26, 2022
A Discord bot for managing ephemeral roles based upon voice channel member presence.
A Discord bot for managing ephemeral roles based upon voice channel member presence.

ephemeral-roles A Discord bot for managing ephemeral roles based upon voice channel member presence. Quickstart Click on the Ephemeral Roles logo head

Dec 19, 2022