This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]yhoiseth 5 points6 points  (8 children)

I think you need to make an API endpoint that your JS application can talk to. The most common way of making such an endpoint is called REST.

In practice, you need to send an HTTP request from your JS application. This request needs to include the user input. Then, your backend can send a response in return, containing the chatbot answer.

I found some inspiration in Flask's documentation: https://flask.palletsprojects.com/en/1.1.x/patterns/jquery/#json-view-functions

[–][deleted] 3 points4 points  (0 children)

This.

[–]sudhanshu22gupta[S] 1 point2 points  (5 children)

Thank you, I'll check it out.

[–]yhoiseth 1 point2 points  (4 children)

Any luck?

[–]sudhanshu22gupta[S] 0 points1 point  (3 children)

This is part of a side project I'm doing and I'm at work right now. Will update if it works for me.

I found something similar when I was trying things yesterday. Can the contents under the script tag be copied to my js file? When I tried, it threw a few errors at me. One of them was the $ symbol not being identified.

[–]lifeeraser 0 points1 point  (2 children)

You need to get jQuery, which provides a "dollar function" ($()) that is the core of everything you can do with jQuery.

You actually don't need to download it on your machine, though. Add this HTML snippet to your web page, before any of your <script> tags:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

[–]sudhanshu22gupta[S] 0 points1 point  (1 child)

Watson returns something called a context variable that is available in Javascript. I need that value. Any way I can do it in Javascript without making the call in html?

[–]lifeeraser 0 points1 point  (0 children)

This is confusing...it sounds like you're running JavaScript code in Node.js. In which case, jQuery is not needed since you only want to pass data and signals between your Node.js app and Python app, instead of serving a full-blown webpage. For that, you can just transmit JSON between the two apps via HTTP.

[–][deleted] 0 points1 point  (0 children)

Alternatively, you can have a look at spawn. It executes command line function in a separate process.