DEPRECATED: You should switch to the official Recast SDK Golang.
Package helping to deal with the Recast.AI Bot Connector
go get -u github.com/yageek/recast-go-bot-connector
package main
import (
"fmt"
"github.com/bmizerany/pat"
"github.com/yageek/recast-go-bot-connector"
)
func main() {
conf := botconn.ConnConfig{
Domain: botconn.RecastAPIDomain,
BotID: "BOT_ID",
UserSlug: "USER_SLUG",
UserToken: "USER_TOKEN",
}
conn := botconn.New(conf)
// Message routing
conn.UseHandler(botconn.MessageHandlerFunc(nextBus))
// Router
mux := pat.New()
mux.Post("/chatbot", conn)
http.HandleFunc("/", mux)
http.ListenAndServe(":8080", nil)
}
func nextBus(w botconn.MessageWriter, m botconn.InputMessage) {
// Handle response
output := botconn.OutputMessage{
Content: "Coucou",
Kind: botconn.TextKind,
}
w.Reply(output)
}
output := botconn.OutputMessage{
Content: "Coucou",
Kind: botconn.TextKind,
}
err := conn.Send(output, "CONVERSATION_ID", "SENDER_ID")
if err != nil {
fmt.Println("Error:", err)
} else {
fmt.Println("Response succeeded")
}
output := botconn.OutputMessage{
Content: "Coucou",
Kind: botconn.TextKind,
}
err := conn.Broadcast(output)
if err != nil {
fmt.Println("Error:", err)
} else {
fmt.Println("Response succeeded")
}