Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: about 18 hours 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 (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-04-28T19:50:10.000Z (5 months ago)
- Last Synced: 2024-09-22T08:02:28.810Z (5 days 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: 164 KB
- Stars: 3
- 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
```goconst (
groupID = 1234568
token = "token"
)type stateFn func(event *gvk.Update) stateFn
type Bot struct {
chatID int64
state stateFn
name stringgvk.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())
}```