daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest Jun 11th, 2018 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top