How to locally store user information when he is using facebook messenger chatbot? - node.js

I followed facebook's documentation and set up my messenger bot. It works fine when it's just me who's using it, but I don't know how to create variables and store information in them locally so that I can have individual information about each user.
For eg. If I ask them to type their phone number, how/where should I save it, so that it isn't overwritten if a new user comes and inputs his number (which happens, if the variable is declared globally), and I can also use it later.
I used Node JS and followed the steps they mentioned in the documentation.

You have node js server as a backend which can communicate to a (mysql/sqlite) database.
Fb provides senderId with each request and also there is another graph API for getting user's other information like Name, Age, Gender, profile pic link etc
https://graph.facebook.com/v2.6/SENDER_ID?access_token=YOUR_TOKEN
You can have a table in your (mysql/sqlite) database where you can store senderId as a unique key and other information including phone number (which you are getting by asking user) in other columns.
Here's the documentation link for public profile API.

Related

Scraping linked-in profile to get user email using NodeJS Puppeteer and scrapedin

Dears, I'm now working on a project that requires me to scrape the public linked-in profiles to get some info like email, name, company, title, photo (some basic information)
I write it with NodeJS, using Puppeteer and library called scrapedin
This library requires me to log in to LinkedIn with e-mail and password, I created a dummy linked-in account to use it for this library, it worked fine in localhost, but once I uploaded it to the server I should use cookies to login
and here is the problem, after maybe 30 min linked-in restricted the account and I can't use it anymore!
How could I solve this problem
Is there another library for linked-in scraping I can use?
Thank you.
LinkedIn likely restricted your account because they don't want bot activity on their website. You could try to make your script act more human, for example by inserting random wait times between actions using setTimeout(). It could also help to spend some time creating a new human-like dummy account that is less easy to detect as a bot, for example by uploading a profile picture and writing some text.
You could also make the script do some human actions like pressing random like buttons between the scrape actions.

How can I increase the 20-minute lifespan of contexts

As I read in the Google documentation “all contexts expire after 20 minutes of becoming active” (https://cloud.google.com/dialogflow/docs/contexts-input-output). What I was wondering is if there is a way to extend this limit. For example, if I store an mp3 playlist in my context so that I can play next audio at the end of the current one, if the duration of the current mp3 exceeds 20 minutes I lose the context and any information on the next mp3.
You need to setup 2 things:
Your own webhook server.
A DB of your preference (I chose MongoDB) to store user data identifyied by an unique chat id, and it can be retrieved diferently from each platform that you integrate your chatbot with.
For example: on facebook you can use the userID of the user that is having a conversation with your bot as uniqueID, on twilio you can use the phonenumber and on your own chat UI for web you can stablish your own ID (usually a timestamp) as a parameter of the request you send to Dialogflow and store it on the localStorage of the client browser. So the next time the user chats with your bot within that same browser, you can get his data by using this uniqueID.
For facebook you can get the userid by using:
agent.originalRequest.payload.data.sender.id
For twilio:
agent.originalRequest.payload.data.From
For web (it depends of the variable that you send to the API)
agent.originalRequest.payload.data.{variable}
Using this uniqueID you can create your own DB registry for each user, get, retrieve or store data and make your contexts stay forever.
PS: Let me know If I was clear, its 4:34 AM lol, I can comment on this to clear any doubts.
Peace!

Dialogflow fulfillment - querying firebase with parameters from user

I am currently working on a dialogflow app for my company. I need to get our app to be able to take any name given by the user and match it to the database.
We manufacture CNC machines and we are attempting to create an application that allows the user to obtain information about their machine using their phone or google home. We have a website that allows them to give their machine a name. This name could be anything. It could be "Zodiac", or it could be "ZMachine #123". This name is stored in the database and is used to reference the machine from the dialogflow app. However, when google parses the voice input, and I get that entity in the fulfilment, I end up with "z machine number 123" or something like that, which I cannot match to the database directly. This is especially true for names that are not standard English words or names, such as a company name or something like that.
I was wondering if anyone had any resources that could point me in the right direction? I noticed that when you name smart devices in google, you can name them anything you like and it still gets it right. What are they doing in the background that allows this to take place?

MS BotFramework Temporary token issue in WebChat URL

I have developed a chatbot using Microsoft BotFramework and node.js and deployed it in webchat. As per this documentation, it is written that the bot's secret 's' can be replaced with a temporary token 't' which is valid for one conversation only.
But the problem is the life span of this token is 30 minutes and within this time window, if some intruder accesses the entire URL: "https://webchat.botframework.com/embed/YOUR_BOT_ID?t=YOUR_TOKEN_HERE&userid=some_user_id" then it is just a child’s play for him to get all of the user’s data because it mimics the chat of the actual user in the other machine.
Is there anything in the BotFramework (apart from DirectLine) that can be done that restricts the URL with the same token to be opened in another machine?
There is an issue on GH which is facing the same event with you, and with the comments, we can found that this situation will not be changed currently.
However, we can get some hints from the comment:
Ultimately, you can't hide the secret/token from clients.
If you want to remove it from the URL, you can host the JS control on your own.
If you want to remove it from page source, you can pass the value in a cookie >and read it in JS in your webpage.
However, in all cases, the value will be available in memory.
I think you can build another simple web site yourself as the bridge from the iframe and yout bot application. You can restrict your user whether is unique in this website's session. And also you can verify your user before instantiate the Bot WebChat.

How do I let the user set a variable with Alexa?

For example, I would like the user to be able to set their home location as a 6 digit number. Then they can just ask my skill for an update, "when's the next bus coming", rather than having to say, "when's the next bus coming to location 123456".
You can persist information using either a database or by passing information along in the session object. There are lots of examples and information about using DynamoDB, such as this Alexa cookbook example.
The session object allows passing data along from each intent to the next, but only persists for the life of the session. The Amazon documentation contains the information about session, but the specifics will depend on the language you are using (eg. Java or NodeJS)

Resources