2016-04-13 05:03:26 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2016-04-13 09:14:23 +03:00
|
|
|
"time"
|
2016-04-13 05:03:26 +03:00
|
|
|
|
|
|
|
"github.com/paked/configure"
|
|
|
|
"github.com/paked/messenger"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
conf = configure.New()
|
|
|
|
verifyToken = conf.String("verify-token", "mad-skrilla", "The token used to verify facebook")
|
|
|
|
verify = conf.Bool("should-verify", false, "Whether or not the app should verify itself")
|
2016-04-13 10:01:42 +03:00
|
|
|
pageToken = conf.String("page-token", "not skrilla", "The token that is used to verify the page on facebook")
|
2016-04-13 05:03:26 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
conf.Use(configure.NewFlag())
|
|
|
|
conf.Use(configure.NewEnvironment())
|
|
|
|
conf.Use(configure.NewJSONFromFile("config.json"))
|
|
|
|
|
|
|
|
conf.Parse()
|
|
|
|
|
2016-04-14 03:25:48 +03:00
|
|
|
m := messenger.New(messenger.Options{
|
2016-04-13 05:03:26 +03:00
|
|
|
Verify: *verify,
|
|
|
|
VerifyToken: *verifyToken,
|
2016-04-13 10:01:42 +03:00
|
|
|
Token: *pageToken,
|
2016-04-13 05:03:26 +03:00
|
|
|
})
|
|
|
|
|
2016-04-13 12:26:31 +03:00
|
|
|
m.HandleMessage(func(m messenger.Message, r *messenger.Response) {
|
2016-04-13 09:14:23 +03:00
|
|
|
fmt.Printf("%v (Sent, %v)\n", m.Text, m.Time.Format(time.UnixDate))
|
2016-04-13 10:01:42 +03:00
|
|
|
fmt.Println(r.Text("Hello, World!"))
|
2016-04-13 12:46:52 +03:00
|
|
|
fmt.Println(m.Attachments)
|
2016-04-13 09:14:23 +03:00
|
|
|
})
|
|
|
|
|
2016-04-13 12:26:31 +03:00
|
|
|
m.HandleDelivery(func(d messenger.Delivery, r *messenger.Response) {
|
2016-04-13 12:36:38 +03:00
|
|
|
fmt.Println(d.Watermark().Format(time.UnixDate))
|
2016-04-13 12:12:23 +03:00
|
|
|
})
|
|
|
|
|
2016-04-13 05:03:26 +03:00
|
|
|
fmt.Println("Serving messenger bot on localhost:8080")
|
2016-04-13 09:14:23 +03:00
|
|
|
|
2016-04-13 05:03:26 +03:00
|
|
|
http.ListenAndServe("localhost:8080", m.Handler())
|
|
|
|
}
|