Using DialogFlow to login in my application - javascript

Well i've searched here and in the documentation of dialogflow and coulnd't find any help in this subject.
I have an aplication and I want to use dialog flow to login in my website, there is a db where my login infos are stored.
So i'm only looking to say to the bot that I want to log in, it will ask my credentials and compare with the ones in my db.
Is there any docs about it? Where could i find something to help me in this?
Perhaps i din't explain well what i want or maybe did something wrong...
Reading through the doc i noticed that i can add js events to the chat...
const dfMessenger = document.querySelector('df-messenger');
dfMessenger.addEventListener('event-type', function (event) {
// Handle event
...
});
Something like this, i grabbed this code from here https://cloud.google.com/dialogflow/es/docs/integrations/dialogflow-messenger#js-events
Can i use this to create a function were i grab the users info and authenticate in my database to login in the application?

This is fairly advanced stuff and I would start with a more basic chatbot before attempting any of this.
I liked Lilis is a first hands in project into dialogflow ES but you could find your own. https://medium.datadriveninvestor.com/build-dialogflow-chatbot-lilis-1-what-are-the-top-seven-minimum-viable-product-features-of-a-998d6bfb60e7
It goes through how to structure a chatbot before how to design it which can be a vital step, limiting the abilities before coding starts.
DialogFlow allows you to make a basic/advanced CA.
User asks a question, CA either replies automatically or fetches a reply.
Dialogflow has a language behind it if you're fetching a reply, Python, Node, Java, C...
All of those languages can connect to a database and check the database parameters on the background once a chatbot gets the propper input then the chatbot can reply based on wether there was a match and the code has done the appropiate changes to the URL, for example.
If you're using the default webhook it needs to be done in node.
Dialogflow can do just about anything that can be done reasonably quick on the background as it supports most of the top coding languages for the replies on the background

Related

Get steamID with Steam API using javascript

First off sorry if this question is a 'bad' one; I am very new to the world of web apps, API's and Javascript.
As the title says I am trying to get a user's steamID using the Steam API using javascript.
This is for a web app that needs to get information about the games a user plays. (Which from my understanding is only obtainable using this special ID.)
My initial thoughts on how to do this would be to use openID so that the user gives Steam their info and the ID is returned to my app.
I have seen that there are lots of examples of this using php; however, because of project requirements, everything must be run in the browser. There is no backend server to even run php on so it is not an option what so ever.
I have spent a better part of a day trying to figure this out and have made no real progress, everything seems to lead back to using php. (maybe what I need under my requirements is not possible?) So an example or anything really would be much appreciated.
welcome to Stack Overflow I can see you are confused as to where to start or progress so here is a basic roadmap:
You will need to contact Steam to get an API key first.
Next part is more tricky for a beginner. You will need to get node.js which is a package manager. Effectively it's a large library of javascript programs which you can import into your own program to do things with. One of these so called "packages" is openid-client, which is an implementation of openID that you can add to your site. Users click on the openID button on your site, it redirects them to steam servers, they login, then your site gets their info without leaking their username or password to you.
Now that you have both the steamID and your API Key your program can input these two into the url steam provides to get owned games. You can input this completed url into fetch or axios (another node package that can request data from servers) and it will respond with the user's owned games in json format.
Here are a list of resources in order to get you started:
https://steamcommunity.com/dev
https://nodejs.org/en/
https://www.npmjs.com/package/openid-client
https://www.npmjs.com/package/node-fetch OR https://www.npmjs.com/package/axios
https://developer.valvesoftware.com/wiki/Steam_Web_API#GetOwnedGames_.28v0001.29
I suggest reading the documentation in each of these links and seeing if there is any youtube tutorials that try and do what you are doing with these technologies to help you implement them as a newbie. Overall there is a lot to learn on each of these technologies but as long as you orient yourself using guides or tutorials you will succeed. Good luck.
Check out this page: How to retrieve Steam username using SteamWorks API?.
However, it seems like an issue you might be having is connecting to the actual API. What exactly are you using for testing?
I know from experience, for example, that you can connect using Postman to various API's, and format a request for them in a chosen language, including JS>

How to integrate a chatbot webhook with a web-based chat window?

I want to develop a web-based chat conversation. I have a Dialogflow webhook that is up and running and that can be easily integrated with, say, facebook messenger or whatsapp, thanks to the functionalities of Dialogflow itself.
Now, say I want to have a web-based chat plugin that I want to interact with said Dialogflow webhook. How does that work, in terms of setup? There are things I know I need, I would like your help to identify things that are still missing and to help me put them all together (conceptually).
I need something to make the chat conversation look pretty; I was hoping there would be some chat plugin online to style messages but the things I could find are always more complicated than that and have functionalities for you to set messages for the plugin to send automatically and things like that.
I need something that is triggered when the user sends a message; when the user sends a message I need to send it to Dialogflow in order to have it fulfilled. Can this be done directly from JS? Or do I have to send some request to my server, which will then call Dialogflow and return the user message?
Is this all I need? I am sorry if this question is too confusing or broad, I'll be glad to give further clarifications as needed.
I think you need this.
https://cloud.google.com/dialogflow/docs/quick/api#detect-intent-text-nodejs
When you use the API for interactions, your service interacts directly with the end-user. For each conversational turn, your service sends end-user expressions to Dialogflow by calling the detectIntent or streamingDetectIntent method of the Sessions type. Dialogflow responds with information about the matched intent, the action, the parameters, and the response defined for the intent. Your service performs actions as needed (for example, database queries or external API calls) and sends a message to the end-user.
It just API interaction with your chat client, you can design the way you want.

How to create a login system that stores user data for beginners?

I'm working on my first web app using ReactJs and have the frontend pretty much done. Now I want to be able to pair the user's data with their username so next time they log in, everything will be exactly as they left it. The user's data is currently all in a JavaScript object so I think I want to save it as a json file. However, I have no clue how to even start this.
My first issue comes with creating the login system. Obviously I cannot just store the username and password in plain text so I would need to encrypt and decrypt it somehow. However, I am currently hosting my site on Netlify so I would need to pass that information over there somehow and the only way I can think of is by adding it to my GitHub repo which is public so anyone can then see my encryption algorithm.
I'm not even sure if this is even how you do it since I've never done anything like this before. Does anyone know where I should start? I don't need something super sophisticated just reasonable.
Probably you can use google's firebase and firestore services. They have an amazing documentation on their website too and there's plenty of resources online. google for firebase authentication tutorial and you'll find a whole lot.

Web site using backbone for frontend and nodejs for backend

I'm developing a new web site that will be a single paged app with some dialog/modal windows. I want to use backbone for frontend. This will call backend using ajax/websockets
and render the resulting json using templates.
As a backend I'll use nodejs express app, that will return the json needed for client, it'll be some kind of api. This will not use server side views.
Client will use facebook, twitter, etc. for authentication and maybe custom registration form.
Client static resources, such as css, js, and html files will be handled by nginx (CDN later).
Questions that I have now:
How can I determine that a given user has the right to do some action in api(i.e. delete a building, create new building)? This is authorization question, I thought of giving user a role when they login and based on it determine their rights. Will this work?
Similar to the above question, will this role based security be enough to secure the api? Or I need to add something like tokens or request signing?
Is this architecture acceptable or I'm over engineering and complicating it?
Passport is an option for the authentication piece of the puzzle. I'm the developer, so feel free to ask me any questions if you use it.
I thought of giving user a role when they login and based on it determine their rights. Will this work?
Yes this will work. You can check for a certain role on the user after it's been fetched from the server. You can then display different UI elements depending on this role.
Will this role based security be enough to secure the api? Or I need to add something like tokens or request signing?
It wont be enough. Anyone could hop into the console and set something like user.admin = true. In your API you'll need to validate a user token from the request, making sure that the related user has the appropriate permissions.
Is this architecture acceptable or I'm over engineering and complicating it?
At the least you should have an API validation layer. That would make a decent enough start, and wouldn't be over-engineering.
For the authentication part of your question i would use everyauth which is an authentication middleware for connect/express. It supports almost every oauth-social-network-thingie.
For role management you could give node-roles a try. I didn't use it myself but it should help you out, because it checks the role on the server side. Of course that is only useful if your API is implemented in node.js. If that's not the case, you have to "proxy" the API calls over your node.js app.
I hope I could help you! :)

Implementing web chat, how do I get typing status?

Can someone illustrate how I can get typing status of the other party with JavaScript?
UPDATE
Can someone recommend a one-to-one open source chatting application, preferably written in PHP? I only found open source chatting rooms which are for chatting among all onliners, but I just need a one-to-one chatting.
Here are a list of PHP-based open-source instant messaging software.
Some of those might be relevant for you.
For example, if you had an text area #chat then you could use this code to attach the event:
document.getElementById('chat').addEventListener('keydown', FUNCTION HERE, false);
See http streaming and some ready solutions here: http://ajaxpatterns.org/HTTP_Streaming
this is how google talk does it. And there are ready php or c++ solutions
It was quie a discovery for me!
This is an update to reflect the significant change in the OP's question:
Google Chat and Facebook both use XMPP(jabber) servers, as do most companies I know of that have internal instant messaging.
The nice part about XMPP is that you get all of the "is typing" and other presence-based information without having to roll-your-own in javascript (bear in mind, you will still need to use javascript to pass XMPP requests back to the server, but XMPP has most of the features you'd need already built in).
Check out OpenFire. It's a great XMPP server, totally open source, and they have a web-based version of their Spark client that is pretty nice.
Or you could get a PHP library for XMPP (there are a few). But you'd still need to have the XMPP server running in the background for PHP to work with.
Here's a list of XMPP libraries for PHP from XMPP.org:
Eiffel
JAXL
Lightr
Missus
xmpphp
Or, if you want to keep things mostly browser-side, they also have a list of libraries for javascript:
dojox.xmpp
js.io
JSJaC
strophe.js
xmpp4gwt
xmpp4js
I made a small chat application a while ago, and the only way to do it is to frequently check for new entries in the chat database and fetch anything newer than the last displayed message. At the same time as all that, you can check to see if the user's input is empty. If it is, do nothing. If it isn't, enter a status code into the database beside that user's name. If anyone has that status in the database when you're fetching information about new messages and who is online, you should display the 'user is typing' message. I hope that makes sense...let me know if it isn't.
For User1: If you save the chat message on each key-press to the database, with a status: sent=false and update the last updated date.
For User2: you could pole periodically for the presence of a message where sent=false and use the last updated to update user is typing message. if the lastupdated date is more than a say ten seconds you could remove the message as that person may have stopped typing. This will allow User2 to see User1 typing, stopping and continueing again.
Ideally polling for this information will be part of an existing call to the database to reduce additional overhead.

Categories

Resources