When I receive a user request I would like to respond with a date with the user timezone. Actually, I can only respond with server TZ
Unfortunately, DialogFlow doesn’t make it easy by simply telling g you what timezone the user is coming from. The best you can do is ask the user for their timezone and then save that to do date/time adjustments in future responses.
This can be optimized a bit for users accessing your agent through Google Assistant by using the new permissions API. See https://chatbotsmagazine.com/personalize-google-assistant-skill-with-user-data-328f5e0860a0
If your user responds to your agent with the parameter of #sys.date-time type, you will receive in your fulfillment the value in ISO-8601 format like "2019-12-17T22:00:00+02:00". The last 6 characters represent a timezone offset. You can use it and calculate the target local time of your users.
Related
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!
We have integrated the NodeJs bot application with the bot framework for interacting with bot in the Microsoft teams.
Based on the user input we are sending the adaptive cards respectively. Currently user can get the adaptive card today and can update the card later that day or after few days.
Is there any way to make the card expire after specific amount of time which make the card disabled.
Thank You
I have an idea how you could do this, but just an fyi that I've not done exactly this before, so there's no guarantee it will work. Basically, you'd be combining the ability to Update a message like discussed here with sending (or in this case 'updating') a pro-active message - see more here on that.
Because this is an existing conversation with the user, you'll have access from any existing message the user sends to get the parameters you need to start your proactive conversation (you need serviceurl, conversationid, tenantid, etc.). Do note that you can send a proactive message from OUTSIDE your bot (the code can be hosted somewhere else, and doesn't need to actually live IN your bot, even though to the user it will appear as if a proactive message was sent from your bot). I mention this because you could have this "expire card" message live in a separate process to your bot.
In case if you are still looking for an answer, I recently tried this approach:
In the card's response data, I set the expiry date and so now when the user submits the card, you can validate the data in the response and then update the card accordingly.
I had to use this approach because we have a very high user base and updating the card for all users proactively took much longer.
Cons: The card will remain will remain active, unless and until the user takes some action on it.
First of all, no this is nothing that is already implemented anywhere and you completely have to build that yourself.
One way to do this is this:
You need to store the activity / message ID for all cards you send. If you have the ID, you can always at any time go back and update the message (ie update your card)
Now that said, what i would suggest is this:
Sent a card to the user and store the id
Store the ID together
with creation date and expiration date somewhere on your end
Have some scheduled process that scans for expired cards
If a card is expired, update the message with a new card saying "sorry this card is expired"
We did that for our MS Teams Bot and its working quite well this way.
I have a webhook designed in Node.js for API.ai that interacts with multiple API's to gather information and give response to user.
Since, I am interacting with multiple API's the response time taken is more than 5 secs which is causing the API.ai request to timeout.
To overcome this, I am trying to implement caching into the node.js webhook which saves the response from API's until a certain amount of time. This will remove timeout until the max-age header time is reached.
Edit: What is the best node module that I can use to cache the API responses for subsequest requests.
Note: I am using request node module for http requests but it doesnt seem to provide a way to cache the response.
All of the answers given are reasonable for tackling the cache problem on the request side. But since you specified API.AI and Actions, you might also be able to, or need to, store information while the conversation is in progress. You can do this using an API.AI context.
It may even be that if you limit it to just one remote call for each response from the user, you might be able to fit it in the timeframe.
For example, if you were having a conversation about movie times and ticket ordering, the conversation may go something like:
User: "I want to see a movie."
[You use an API to lookup the nearest theater, store the theater's location in a context and reply] "Your nearest theater is the Mall Megaplex. Are you interested in one there?"
User: "Sure"
[You now already have the theater, so you query for what it is playing with another API call and store it in a context] "There are seven different movies playing, including Star Wars and Jaws. Do those sound interesting?"
User: "No"
[You already have the data in the context, so you don't need another call.] "How about Rocky or..."
In this way you're making the same number of calls (generally), but storing the user's results in the session as you go as opposed to collecting all the information for the user, or all the possible results, and then narrowing them.
Finally decided to use the below module:
https://www.npmjs.com/package/memory-cache
This served my scenario better. Might try using Redis soon when i get some time.
Currently i am using Bot Framework with Node for my chat bot and i am using API AI as my Natural Language Processing.
My question is, let say the user replied with "yesterday" or "today" or "tomorrow" and it is base on the server time. Now, it will go wrong if a person in Australia says today at 6 AM in the morning and their time which is in GMT will still be previous day and this gives a wrong date.
May i have suggestion on how do i solve this timezone issue?
Each API.AI agent has a default time zone setting which can be altered in your agents settings (documentation here) which will be used to determine the meaning of user's date/time queries like "tomorrow" and "yesterday" and "3pm":
If you're using API.AI's /query API you can send the timezone parameter in the request JSON to indicate what timezone the user you are sending the request on behalf of is in.
I have deployed my api.ai bot with gupshup.io platform but the problem i am facing is that when i send a message through gupshup.io and check its response on heroku server, it sets all my parameter (which were supposed to be saved in context) as null.
While when i send the same message on api.ai, it works well (saves the values of variable in context).
I am unable to understand that why on gupshup.io, the api.ai bot is unable to send values of the variables during conversation.
Are you using the API.ai template on Gupshup.io? If yes, then this could be a problem due to the session ID which is unique for every message from the user. Hence every message is treated as a new message by api.ai
Check out the solution here in another thread -
Maintaining session in Gupshup bot calls to Api.ai
Do let me know if this helps.
it took me a bit to figure it out too but the trick is to have a unique ID but one which isn't unique all the time. In other words, there is 1 variable that is unique and at the same time never changes per user -> phone number.
You can use the phone number that is being passed (or sender id) and that will create unique sessions and at the same time, it will keep them persistent with the same person (so you don't lose context).