Advertisement
Guest User

Untitled

a guest
Jun 11th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.18 KB | None | 0 0
  1. func (df *DFClient) DetectIntents() {
  2.  
  3.     for req := range df.RequestChannel {
  4.         go func() {
  5.             // TODO implement intent requests
  6.             temp := df.getIntent(
  7.                 viper.GetString(agent),
  8.                 strconv.Itoa(int(req.ID)), // TODO CHECK THIS CONVERSION
  9.                 viper.GetString(lang),
  10.                 req.Request,
  11.             )
  12.  
  13.             req.Response = temp.QueryResult.FulfillmentText
  14.             req.Intent = temp.QueryResult.Intent.Name
  15.             req.Confidence = temp.QueryResult.IntentDetectionConfidence
  16.             df.ResponseChannel <- req
  17.  
  18.         }()
  19.     }
  20. }
  21.  
  22. //Utility wrapper to get response from DialogFlowClient when parsing text messages.
  23. func (df *DFClient) getIntent(BotId string, DFSessionID string, LangCode string, msg string) *dfproto.DetectIntentResponse {
  24.     req := &dfproto.DetectIntentRequest{
  25.         Session:     "projects/" + BotId + "/agent/sessions/" + DFSessionID,
  26.         QueryParams: &dfproto.QueryParameters{},
  27.         QueryInput: &dfproto.QueryInput{
  28.             Input: &dfproto.QueryInput_Text{
  29.                 Text: &dfproto.TextInput{
  30.                     Text:         msg,
  31.                     LanguageCode: LangCode,
  32.                 },
  33.             },
  34.         },
  35.     }
  36.     fmt.Println(req)
  37.     res, err := df.SessionClient.DetectIntent(context.Background(), req)
  38.  
  39.     if err != nil {
  40.         log.Fatal(err)
  41.     }
  42.     return res
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement