This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func cardFromDrink(d *cocktail.FullDrink) df.BasicCard { | |
| card := df.BasicCard{ | |
| Title: d.StrDrink, | |
| FormattedText: d.StrInstructions, | |
| Image: &df.Image{ | |
| ImageURI: d.StrDrinkThumb, | |
| }, | |
| } | |
| return card | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func search(c *gin.Context, dfr *df.Request) { | |
| } | |
| func random(c *gin.Context, dfr *df.Request) { | |
| } |
NewerOlder