Giter Site home page Giter Site logo

Comments (10)

ar7hur avatar ar7hur commented on July 22, 2024

Hi Andrew,

We've been thinking about CORS for a while. Our concern is that your authorization access token would be visible to your website visitors. That's why we thought a proxy would be better (of course it comes with so drawbacks, like latency and having to set it up).

Since the same access token enables you to access the REST API for potential write operations on your instance, it's really not possible to make it public in your HTML code. Later, we may use several access tokens with different scopes, one of them being restricted to GET/message, that you could use for CORS.

If somebody has a better idea, please let us know.

from wit.

andrewserff avatar andrewserff commented on July 22, 2024

I was worried about that too, but for prototyping purposes, it wouldn't be a concern (which is where I'm at right now). Have you considered JSONP at all?

from wit.

blandinw avatar blandinw commented on July 22, 2024

We do support JSONP, as an experimental feature.
However, you can't use headers with JSONP, so you'll need to pass the access token as a 'access_token' query parameter.

Also, you want to use a GET request here.

from wit.

guillaume86 avatar guillaume86 commented on July 22, 2024

Can you provide a JSONP sample? I tried providing an access_token get parameter but I get a HTTP/1.1 403 Forbidden

from wit.

Weirche avatar Weirche commented on July 22, 2024

Hi Guillaume,

Here is a jsonp example using jquery

<!doctype html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Demo</title>
</head>
<body>
    <script src="jquery.js"></script>
    <script>
    handleResult = function(textResult) {
        $.ajax({
            url: 'https://api.wit.ai/message',
            data: {
                'q': textResult,
                'access_token' : "YOUR_TOKEN"
            },
            dataType: "jsonp",
            jsonp: "callback",
            method: 'POST',
            success: function( response ) {
                console.log( response ); // server response
            }
        })}
    handleResult("Book meeting with Henri tomorrow at 5pm");
    </script>
</body>
</html>

Let me know if it works for you.

from wit.

guillaume86 avatar guillaume86 commented on July 22, 2024

Thanks. I tried but neither jQuery 2.x nor AngularJS allowed me to POST JSONP requests, I'm not sure where the probleme come from, perhaps Chrome specific, I'll take a look later.

Edit: ok actually it can't work since JSONP just use a script tag wich will make a GET

from wit.

murat0658 avatar murat0658 commented on July 22, 2024

any update? how can we use "POST" method in Ajax, jQuery. We tried JSONP before and it gave bad URL exception.

from wit.

blandinw avatar blandinw commented on July 22, 2024

JSONP can only be used with GET. If you really want CORS, please reopen an issue and we'll leave it open as a feature request to see if it gains traction

from wit.

murat0658 avatar murat0658 commented on July 22, 2024

ok. thank you. i will ask another: is there any other way of getting bot's response to my query in my web site?
capture

from wit.

blandinw avatar blandinw commented on July 22, 2024

You can use the GET /message API from your website, as this does not require CORS.
You'll need to write some code to generate a bot answer from the intent and entities you extract.

CORS support has been requested here #242 by the way

from wit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.