Skip to content

Instantly share code, notes, and snippets.

View depado's full-sized avatar
😁
Coding and Writing Posts

depado

😁
Coding and Writing Posts
View GitHub Profile
func specify(c *gin.Context, dfr *df.Request) {
var err error
var p searchParams
if err = dfr.GetContext("Search-followup", &p); err != nil {
logrus.WithError(err).Error("Couldn't get parameters")
c.AbortWithStatus(http.StatusBadRequest)
return
}
type searchParams struct {
Alcohol string `json:"alcohol"`
DrinkType string `json:"drink-type"`
Name string `json:"name"`
}
func search(c *gin.Context, dfr *df.Request) {
var err error
var p searchParams
out := fmt.Sprintf("I found that cocktail : %s", d.StrDrink)
dff := &df.Fulfillment{
FulfillmentMessages: df.Messages{
{RichMessage: df.Text{Text: []string{out}}},
df.ForGoogle(cardFromDrink(d)),
},
}
c.JSON(http.StatusOK, dff)
func cardFromDrink(d *cocktail.FullDrink) df.BasicCard {
card := df.BasicCard{
Title: d.StrDrink,
FormattedText: d.StrInstructions,
Image: &df.Image{
ImageURI: d.StrDrinkThumb,
},
}
return card
}
// Platform is a simple type intended to be used with responses
type Platform string
// Platform constants, used in the webhook responses
const (
Unspecified Platform = "PLATFORM_UNSPECIFIED"
Facebook Platform = "FACEBOOK"
Slack Platform = "SLACK"
Telegram Platform = "TELEGRAM"
Kik Platform = "KIK"
// Message is a struct holding a platform and a RichMessage.
// Used in the FulfillmentMessages of the response sent back to dialogflow
type Message struct {
Platform
RichMessage RichMessage
}
func webhook(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{})
}
func main() {
r := gin.Default()
r.POST("/webhook", webhook)
if err := r.Run("127.0.0.1:8001"); err != nil {
panic(err)
}
out := fmt.Sprintf("I found that cocktail : %s", d.StrDrink)
dff := &df.Fulfillment{
FulfillmentMessages: df.Messages{
{RichMessage: df.Text{Text: []string{out}}},
df.ForGoogle(df.SingleSimpleResponse(out, out)),
},
}
c.JSON(http.StatusOK, dff)
func random(c *gin.Context, dfr *df.Request) {
var err error
var d *cocktail.FullDrink
if d, err = cocktail.C.GetRandomDrink(); err != nil {
logrus.WithError(err).Error("Coudln't get random drink")
c.AbortWithStatus(http.StatusInternalServerError)
return
}
fmt.Println(d)
func search(c *gin.Context, dfr *df.Request) {
}
func random(c *gin.Context, dfr *df.Request) {
}