diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2019-08-09 02:02:05 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2019-08-09 02:02:05 +0300 |
commit | 94c96cef29cd83bc60b2eabb8bb89c9fd8c7059b (patch) | |
tree | 676b3e2b6ffb171e102931e5fac01f7a4621c20a /examples/example_1.go | |
parent | d13acd7da9bd1c08de33b91120a479df88d21db2 (diff) |
0.1.8 Release
Diffstat (limited to 'examples/example_1.go')
-rw-r--r-- | examples/example_1.go | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/examples/example_1.go b/examples/example_1.go deleted file mode 100644 index 5c03063..0000000 --- a/examples/example_1.go +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Webhook example - */ -package main - -import ( - "fmt" - "github.com/neonxp/tamtam" - "log" - "net/http" - "os" -) - -func main() { - // Initialisation - api := tamtam.New(os.Getenv("TOKEN")) - - // Some methods demo: - info, err := api.GetMe() - log.Printf("Get me: %#v %#v", info, err) - chats, err := api.GetChats(0, 0) - log.Printf("Get chats: %#v %#v", chats, err) - chat, err := api.GetChat(chats.Chats[0].ChatId) - log.Printf("Get chat: %#v %#v", chat, err) - msgs, err := api.GetMessages(chats.Chats[0].ChatId, nil, 0, 0, 0) - log.Printf("Get messages: %#v %#v", msgs, err) - subs, _ := api.GetSubscriptions() - for _, s := range subs.Subscriptions { - _, _ = api.Unsubscribe(s.Url) - } - subscriptionResp, err := api.Subscribe("https://576df2ec.ngrok.io/webhook", []string{}) - log.Printf("Subscription: %#v %#v", subscriptionResp, err) - - ch := make(chan interface{}) // Channel with updates from TamTam - - http.HandleFunc("/webhook", api.GetHandler(ch)) - go func() { - for { - upd := <-ch - log.Printf("Received: %#v", upd) - switch upd := upd.(type) { - case tamtam.UpdateMessageCreated: - res, err := api.SendMessage(0, upd.Message.Sender.UserId, &tamtam.NewMessageBody{ - Text: fmt.Sprintf("Hello, %s! Your message: %s", upd.Message.Sender.Name, upd.Message.Body.Text), - }) - log.Printf("Answer: %#v %#v", res, err) - default: - log.Printf("Unknown type: %#v", upd) - } - } - }() - - http.ListenAndServe(":10888", nil) -} |