https://github.com/vildan-valeev/gvk
Golang library for using Chat bot API vk.com
https://github.com/vildan-valeev/gvk
api api-client chatbot client-api fsm-library golang state-machine vk-api vk-bot vkontakte vkontakte-api
Last synced: 4 months ago
JSON representation
Golang library for using Chat bot API vk.com
- Host: GitHub
- URL: https://github.com/vildan-valeev/gvk
- Owner: vildan-valeev
- License: lgpl-3.0
- Created: 2023-04-26T11:25:30.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2025-01-25T17:28:13.000Z (over 1 year ago)
- Last Synced: 2025-05-07T06:04:29.862Z (about 1 year ago)
- Topics: api, api-client, chatbot, client-api, fsm-library, golang, state-machine, vk-api, vk-bot, vkontakte, vkontakte-api
- Language: Go
- Homepage: https://dev.vk.com/ru/api/bots/getting-started
- Size: 165 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: COPYING.LESSER
Awesome Lists containing this project
README
# GVK - golang vk api
Library with states, goroutines
## Example
```go
const (
groupID = 1234568
token = "token"
)
type stateFn func(event *gvk.Update) stateFn
type Bot struct {
chatID int64
state stateFn
name string
gvk.API
}
func newBot(chatID int64) gvk.Bot {
b := &Bot{
chatID: chatID,
API: gvk.NewAPI(token),
}
b.state = b.EntryHandler
return b
}
func (b *Bot) Update(update *gvk.Update) {
b.state = b.state(update)
}
func (b *Bot) EntryHandler(update *gvk.Update) stateFn {
if strings.HasPrefix(update.Object.MessageNew.Message.Text, "ping") {
b.MessagesSend(&gvk.MessagesSendOptions{Message: "pong", UserID: b.chatID})
return b.handleNext
}
b.MessagesSend(&gvk.MessagesSendOptions{Message: "not understand...", UserID: b.chatID})
return b.EntryHandler
}
func (b *Bot) handleNext(update *gvk.Update) stateFn {
b.MessagesSend(&gvk.MessagesSendOptions{
Message: "pong again )))",
UserID: b.chatID,
})
return b.EntryHandler
}
func main() {
fmt.Print("Start!")
dsp, err := gvk.NewDispatcher(token, groupID, newBot)
log.Println(err)
log.Println(dsp.Poll())
}
```