0

How would I be able to make an API request to detect intent (I need just that) with Google Dialogflow?

The problem I have is that - I cannot use any library (enclosed system that I cannot just add any library I want to it) I can ONLY make REST requests and authenticate with Oauth1.0/Keys and possibly Oauth2.0 as well.

What would I need to do to make such a request with these limitations?

Thanks in advance,

makat
  • 154
  • 1
  • 3
  • 14
  • FYI: OAuth 1.0 is deprecated and is not used in Google Cloud. Making REST API calls is easy, but using the Client SDKs is better. Why reinvent the wheel and introduce your own bugs. – John Hanley Jan 31 '20 at 21:58
  • I understand, but I can't use the Client SDK - I only have access to REST API calls - system limitations – makat Feb 01 '20 at 12:28
  • Review the API documentation and write some code. Then post a question when you have actual code that you need help with. https://cloud.google.com/dialogflow/docs/reference/rest/v2-overview – John Hanley Feb 01 '20 at 15:42
  • @JohnHanley I don't think you understood my question.. I won't start writing code before I know I can authenticate within my specific environment - In my environment I have no access to modifying the code of the authentication, it's basically a dropdown list with options, that is why I am asking if it is at all possible to authenticate with simple oAuth2.0 or anything of that sort working ONLY with REST requests – makat Feb 02 '20 at 10:55
  • Possible Duplicate of:, https://stackoverflow.com/questions/48201131/how-to-access-dialogflow-v2-api-from-a-webpage/57249798#57249798 – Nikhil Savaliya Feb 03 '20 at 03:50
  • https://chatbotslife.com/dialogflow-v2-rest-api-communication-6cf7ab66ab36 here is example – Nikhil Savaliya Feb 03 '20 at 03:50
  • Does this answer your question? [How to access Dialogflow V2 API from a webpage?](https://stackoverflow.com/questions/48201131/how-to-access-dialogflow-v2-api-from-a-webpage) – Paddy Popeye Feb 05 '20 at 11:29

1 Answers1

0

Try this (this uses a native .net library) - I'm using .net core 3.1 but I believe it should work in other versions. You need Json.Net to parse the answer. This uses oAuth 2.0 as 1.0 has been deprecated.

 dynamic results;
    string url = @"https://api.dialogflow.com/v1/intents/<intentId>";

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    request.Headers.Add(HttpRequestHeader.Authorization, "Bearer <your dialogflow developer key>");

    try
    {
        WebResponse response = request.GetResponse();
        using (Stream responseStream = response.GetResponseStream())
        {
            StreamReader reader = new StreamReader(responseStream, System.Text.Encoding.UTF8);
            var restResponse = reader.ReadToEnd();
            results = JsonConvert.DeserializeObject<dynamic>(restResponse);
    }
    catch (WebException ex)
    {
        WebResponse errorResponse = ex.Response;
        using (Stream responseStream = errorResponse.GetResponseStream())
        {
            StreamReader reader = new StreamReader(responseStream, System.Text.Encoding.GetEncoding("utf-8"));
            String errorText = reader.ReadToEnd();
        }
        throw;
    }
Ray
  • 483
  • 4
  • 17