Skip to content

Commit

Permalink
bump go version, update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
vildan-valeev committed Apr 28, 2024
1 parent 77c8e0f commit 4ffef19
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 49 deletions.
2 changes: 1 addition & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

const (
APIVersion = "5.131"
APIVersion = "5.199"
)

// https://dev.vk.com/ru/api/community-messages/getting-started#Доступные инструменты и методы
Expand Down
9 changes: 1 addition & 8 deletions example/echo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ import (
"github.com/vildan-valeev/gvk"
)

//
//const (
// groupID = 194299208
// token = "vk1.a.8-WDS15nXOxt3wU9pfCOHjAt0e7LiOZl8_u_su7PzFXVcgRgpJXZbDOB_cpBVKPOitdfTi9_Bp-oGQbrEeRr_ozjdHB3tbCtJOQFSe6VSEfX5C_IzvEUqZ3xnPlODyQTohFEh-EzhP9CcQEK5Ei6s0Xwy2L3JRSYIoup2wZFApIhpkGDTU5tdvQ09Skz7qMO3eg8fmqpM6jIzMfBIkZR6A"
// tokenPosting = "vk1.a.F3PWupGyC4SKUFgQs51H1u7NOXcm8uWweVusWkmzWDwZha2uUzCeAItJGq4GBbwSQEnqIrHvVph6tt5xaHOc5w96q0GVKgJShvtUEIjtcEgj81CzXeaN8nJLEjrKN6ZVxpTU54Id45JOhY3sFBxg1giD45JxclmQXrk9FYxem6aRmXTpkSq-9hPnxuTyu5wb"
//)

type stateFn func(event *gvk.Update) stateFn

type Bot struct {
Expand Down Expand Up @@ -61,7 +54,7 @@ func (b *Bot) handleNext(update *gvk.Update) stateFn {
}

func main() {
fmt.Print("Start!")
fmt.Println("Start!")

dsp, err := gvk.NewDispatcher(token, groupID, newBot)

Expand Down
5 changes: 0 additions & 5 deletions example/keyboards/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ import (
"github.com/vildan-valeev/gvk"
)

//const (
// groupID = 194299208
// token = "b30fae3f8d488e20cdbe041cbec9a0aa62e7c52e6107f97f97a9fd9007abe32223e1373cce590bfabf374"
//)

type stateFn func(event *gvk.Update) stateFn

type Bot struct {
Expand Down
5 changes: 0 additions & 5 deletions example/sessions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import (
"github.com/vildan-valeev/gvk"
)

//const (
// groupID = 194299208
// token = "b30fae3f8d488e20cdbe041cbec9a0aa62e7c52e6107f97f97a9fd9007abe32223e1373cce590bfabf374"
//)

type stateFn func(event *gvk.Update) stateFn

type Bot struct {
Expand Down
63 changes: 34 additions & 29 deletions example/wall/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ import (
"strings"
)

//const (
// groupID = 194299208
// token = "vk1.a.8-WDS15nXOxt3wU9pfCOHjAt0e7LiOZl8_u_su7PzFXVcgRgpJXZbDOB_cpBVKPOitdfTi9_Bp-oGQbrEeRr_ozjdHB3tbCtJOQFSe6VSEfX5C_IzvEUqZ3xnPlODyQTohFEh-EzhP9CcQEK5Ei6s0Xwy2L3JRSYIoup2wZFApIhpkGDTU5tdvQ09Skz7qMO3eg8fmqpM6jIzMfBIkZR6A"
// tokenPosting = "vk1.a.aeQLjRCZN_9B7QfHcz7XJYeRuVr6ty6qgYP6QJ7k-qURVARGmeAFK-VEoIyoK1Qit6sRUxEcC71w7fxZJeUTKbyxY2MffdW8wSN4zU6zT1I31GeUM081O59pa8n_aVwx86QWXVYbP81TiEGd9GIoJ5V3mxyPgJDuGHT0FBlkhvjr1ZJjbGZ7EjJQPdZZ7BSQ"
//)

type stateFn func(event *gvk.Update) stateFn

type Bot struct {
Expand All @@ -39,37 +33,48 @@ func (b *Bot) Update(update *gvk.Update) {
}

func (b *Bot) EntryHandler(update *gvk.Update) stateFn {
if strings.HasPrefix(update.Object.MessageNew.Message.Text, "ping") {
poster := gvk.NewAPI(tokenPosting)
opt := gvk.WallPostOptions{
Message: "pong",
OwnerID: -groupID,
FromGroup: 1,
}
post, err := poster.WallPost(&opt)
if err != nil {
log.Fatalln(err)
if update.Object.MessageNew != nil {
if strings.HasPrefix(update.Object.MessageNew.Message.Text, "ping") {
b.MessagesSend(&gvk.MessagesSendOptions{Message: "pong to channel...", UserID: b.chatID})

poster := gvk.NewAPI(tokenPosting) // https://oauth.vk.com/authorize?client_id=APP_ID&display=page&redirect_uri=https://oauth.vk.com/blank.html&scope=wall,offline&response_type=token&v=5.199
opt := gvk.WallPostOptions{
Message: "pong 1",
OwnerID: -groupID,
FromGroup: 1,
}

post, err := poster.WallPost(&opt)
log.Println(post.Response.PostID)
if err != nil {
log.Println(err)
}

return b.handleNext
}
b.postID = post.Response.PostID

b.MessagesSend(&gvk.MessagesSendOptions{Message: "pong to channel...", UserID: b.chatID})
return b.handleNext
b.MessagesSend(&gvk.MessagesSendOptions{Message: "not understand...", UserID: b.chatID})
}

b.MessagesSend(&gvk.MessagesSendOptions{Message: "not understand...", UserID: b.chatID})

return b.EntryHandler
}

func (b *Bot) handleNext(update *gvk.Update) stateFn {

poster := gvk.NewAPI(tokenPosting)
opt := gvk.WallEditOptions{
Message: "update pong",
OwnerID: -groupID,
PostID: b.postID,
opt := gvk.WallPostOptions{
Message: "pong 2",
OwnerID: -groupID,
FromGroup: 1,
}
_, err := poster.WallEdit(&opt)
log.Println(b.postID, err)

post, err := poster.WallPost(&opt)

if err != nil {
log.Println(err)
}
log.Println(post.Response.PostID)

b.MessagesSend(&gvk.MessagesSendOptions{
Message: "pong again )))",
UserID: b.chatID,
Expand All @@ -79,7 +84,7 @@ func (b *Bot) handleNext(update *gvk.Update) stateFn {
}

func main() {
fmt.Println("Start!")
fmt.Println("Start wall!")

dsp, err := gvk.NewDispatcher(token, groupID, newBot)

Expand All @@ -88,5 +93,5 @@ func main() {
}

/*
https://api.vk.com/method/wall.edit?access_token=vk1.a.69WlhlECCfNrz2kJvBFvOwKYmlNay-RZ-w4HoTMoUu9_i_TDABY9Y_vevyXh3z3BystqsMFH_pDIxMLDjHSROZCOcpwPpHet10cQNi4LMCpYPPAy2EfpUPL0sUUZSLZp807xabogflTr3wtOV0y7d9ngDOZ1DFeRbhkFiveIV8ls0Op_EWcKcCOnN0c5saMXufUjs_5FaMqOVBerfmCxKg&message=Откликнуться&owner_id=-194299208&post_id=206&v=5.199
https://api.vk.com/method/wall.edit?access_token=token&message=Откликнуться&owner_id=-194299208&post_id=206&v=5.199
*/
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/vildan-valeev/gvk

go 1.21
go 1.22

0 comments on commit 4ffef19

Please sign in to comment.