aboutsummaryrefslogtreecommitdiff
path: root/examples/example.go
diff options
context:
space:
mode:
authorAlexander Kiryukhin <a.kiryukhin@mail.ru>2019-08-09 17:52:33 +0300
committerAlexander Kiryukhin <a.kiryukhin@mail.ru>2019-08-09 17:52:48 +0300
commitb87e42f3294318244deae8126b3ac18d543fd3d7 (patch)
tree2b4fe1f84b07ddf80a6cb863c385293c5d2c4496 /examples/example.go
parenta8ca31679d01ddfe461cadb994131986639b4ea1 (diff)
fix uploadsv0.2.0
Diffstat (limited to 'examples/example.go')
-rw-r--r--examples/example.go31
1 files changed, 26 insertions, 5 deletions
diff --git a/examples/example.go b/examples/example.go
index b4e84ac..8effc67 100644
--- a/examples/example.go
+++ b/examples/example.go
@@ -1,5 +1,3 @@
-// +build ignore
-
package main
import (
@@ -32,6 +30,9 @@ func main() {
AddLink("Библиотека", tamtam.POSITIVE, "https://github.com/neonxp/tamtam").
AddCallback("Колбек 1", tamtam.NEGATIVE, "callback_1").
AddCallback("Колбек 2", tamtam.NEGATIVE, "callback_2")
+ keyboard.
+ AddRow().
+ AddCallback("Картинка", tamtam.POSITIVE, "picture")
// Отправка сообщения с клавиатурой
res, err := api.Messages.SendMessage(0, upd.Message.Sender.UserId, &tamtam.NewMessageBody{
@@ -42,10 +43,30 @@ func main() {
})
log.Printf("Answer: %#v %#v", res, err)
case *tamtam.MessageCallbackUpdate:
- res, err := api.Messages.SendMessage(0, upd.Callback.User.UserId, &tamtam.NewMessageBody{
- Text: "Callback: " + upd.Callback.Payload,
- })
+ // Ответ на коллбек
+ attachments := make([]interface{}, 0)
+ if upd.Callback.Payload == "picture" {
+ photo, err := api.Uploads.UploadPhoto("./examples/example.jpg")
+ if err != nil {
+ log.Fatal(err)
+ }
+ attachments = append(attachments, tamtam.NewPhotoAttachmentRequest(tamtam.PhotoAttachmentRequestPayload{Photos: photo.Photos}))
+ }
+ res, err := api.Messages.AnswerOnCallback(
+ upd.Callback.CallbackID,
+ &tamtam.CallbackAnswer{
+ UserId: upd.Callback.User.UserId,
+ Message: &tamtam.NewMessageBody{
+ Text: "OK!",
+ },
+ Notification: "Callback is ok",
+ })
log.Printf("Answer: %#v %#v", res, err)
+ res2, err := api.Messages.SendMessage(0, upd.Callback.User.UserId, &tamtam.NewMessageBody{
+ Text: upd.Callback.Payload + " at " + upd.GetUpdateTime().String(),
+ Attachments: attachments,
+ })
+ log.Printf("Answer: %#v %#v", res2, err)
default:
log.Printf("Unknown type: %#v", upd)
}