vk

package module
v0.0.0-...-80b8f90 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2022 License: BSD-3-Clause Imports: 8 Imported by: 0

README

Joe Bot - VK Adapter

Connecting joe with the VK chat application. https://github.com/go-joe/joe


This repository contains a module for the Joe Bot library. Built using vksdk.

Getting Started

This library is packaged using Go modules. You can get it via:

go get github.com/tdakkota/joe-vk-adapter

Example usage

In order to connect your bot to VK you can simply pass it as module when creating a new bot:

package main

import (
	"os"

	"github.com/go-joe/joe"
	"github.com/tdakkota/joe-vk-adapter"
)

func main() {
	b := joe.New("example-bot",
		vk.Adapter(os.Getenv("BOT_TOKEN")),
	…
	)

	b.Respond("ping", func(msg joe.Message) error {
		msg.Respond("pong")
		return nil
	})

	err := b.Run()
	if err != nil {
		b.Logger.Fatal(err.Error())
	}
}

This adapter will emit the following events to the robot brain:

  • joe.ReceiveMessageEvent
  • ChatCreateEvent
  • ChatTitleUpdateEvent
  • ChatPhotoUpdateEvent
  • ChatPinUpdateEvent
  • UserEnteredChatEvent
  • UserLeavedChatEvent

License

BSD-3-Clause

Documentation

Overview

Package vk implements a VK adapter for the joe bot library.

Index

Constants

This section is empty.

Variables

View Source
var ErrGetBotInfo = errors.New("failed to get bot info")

Functions

func Adapter

func Adapter(token string, opts ...Option) joe.Module

Adapter returns a new vk Adapter as joe.Module.

Types

type BotAdapter

type BotAdapter struct {
	// contains filtered or unexported fields
}

BotAdapter implements a joe.Adapter that reads and writes messages to and from VK.

func NewAdapter

func NewAdapter(ctx context.Context, conf Config) (*BotAdapter, error)

NewAdapter creates a new *BotAdapter that connects to VK. Note that you will usually configure the VK adapter as joe.Module (i.e. using the Adapter function of this package).

func (*BotAdapter) Close

func (b *BotAdapter) Close() error

Close disconnects the adapter from the vk API.

func (*BotAdapter) RegisterAt

func (b *BotAdapter) RegisterAt(brain *joe.Brain)

RegisterAt implements the joe.Adapter interface by emitting the vk API events to the given brain.

func (*BotAdapter) Send

func (b *BotAdapter) Send(text, chat string) error

Send implements joe.Adapter by sending all received text messages to the given chat.

type ChatCreateEvent

type ChatCreateEvent struct {
	Channel string // The id of created channel.
	Text    string // Chat title

	// original response (objects.MessageNewObject)
	Data interface{}
}

ChatCreateEvent struct

type ChatPhotoUpdateEvent

type ChatPhotoUpdateEvent struct {
	Channel  string                            // The id of created channel.
	NewPhoto object.MessagesMessageActionPhoto // The object with new cover photo urls
	Removed  bool                              // true if cover photo has changed, otherwise false

	// original response (objects.MessageNewObject)
	Data interface{}
}

ChatPhotoUpdateEvent struct

type ChatPinUpdateEvent

type ChatPinUpdateEvent struct {
	Channel   string // The id of created channel.
	UserID    string // A string identifying the user who changed pin
	MessageID string // A string identifying the changed pin message
	Unpinned  bool   // true if message has unpinned, otherwise false

	// original response (objects.MessageNewObject)
	Data interface{}
}

ChatPinUpdateEvent struct

type ChatTitleUpdateEvent

type ChatTitleUpdateEvent struct {
	Channel string // The id of created channel.
	NewText string // New chat title

	// original response (objects.MessageNewObject)
	Data interface{}
}

ChatTitleUpdateEvent struct

type Config

type Config struct {
	Token  string
	Logger *zap.Logger
}

Config contains the configuration of a BotAdapter.

type Option

type Option func(*Config) error

An Option is used to configure the vk adapter.

func WithLogger

func WithLogger(logger *zap.Logger) Option

WithLogger can be used to inject a different logger for the vk adapater.

type UserEnteredChatEvent

type UserEnteredChatEvent struct {
	Channel string // The channel over which the message was received.
	UserID  string // A string identifying the new user in chat
	ByLink  bool

	// original response (objects.MessageNewObject)
	Data interface{}
}

UserEnteredChatEvent struct

type UserLeavedChatEvent

type UserLeavedChatEvent struct {
	Channel string // The channel over which the message was received.
	UserID  string // A string identifying the leaved user in chat

	// original response (objects.MessageNewObject)
	Data interface{}
}

UserLeavedChatEvent struct

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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