How to clear state in botkit 4 conversation - botkit

We have built a bot using botkit v4 and we are using it with Facebook messenger.
We want to clear the state on a specific facebook_postback.
I tried the following but nothing is working.
bot.controller.storage.delete(message.user)
I did not find any proper references in the documents as well. any help will be appreciated.
Ref: https://learn.microsoft.com/en-us/javascript/api/botbuilder-core/storage?view=botbuilder-ts-latest#delete-string---

Storage.delete method takes a list of identifiers, so correct syntax is
bot.controller.storage.delete([itemId]);
Also you need to discover correct format for itemId,
I have an example from websocket controller and it looks like this:
websocket/conversations/USERID-USERID/
The final syntax would look like this:
const itemId = 'facebook/conversations/' + message.user + '-' + message.user + '/';
await bot.controller.storage.delete([itemId]);

Related

why using var {google} instead of var google in google.auth.OAuth

This code is from oauth nodesjs.
I want to ask why we are using '{}' around the var google? I also tried using it without '{}' and got error OAuth2 is undefined. i can't understand what is happening here.
var {google} = require('googleapis');
var OAuth2 = google.auth.OAuth2;
To add a little to this answer - this is what's called a destructuring assignment. You can read about them here:
http://2ality.com/2015/01/es6-destructuring.html
The code you're looking at here:
const {google} = require('googleapis');
Is the same as code that looks like this:
const google = require('googleapis').google;
This is just a convenient shorthand that was added in es6. We made the change in the googleapis package when we moved towards ES modules, which don't play nicely with the export=foo style syntax. Hope this helps!
According to the Changelog from google-api-nodejs-client, there are some changes from V26.0.0 onwards that you have to implement in your code, precisely the issue you are experiencing is mentioned. I also took a while to figure this one out...
BREAKING CHANGE: This library is now optimized for es6 modules. In previous versions you would import the library like this:
const google = require('googleapis');
In this and future versions, you must use a named import:
const {google} = require('googleapis');
You may also reference the type to instantiate a new instance:
const {GoogleApis} = require('googleapis');
const google = new GoogleApis();

How to get the mentioned users from react draft-js-mention-plugin?

I gone through the documentation of draft-js-mention-plugin but couldn't figure a way to read all the mentions from the content. Is there a way can find all the mentions as array?. I need to store all the mentions seperately and send email.Your help is highly appreciated. I am using the example given in here
You can do like below :
const rawEditorContent = convertToRaw(this.state.editorState.getCurrentContent());
const entityMap = rawEditorContent.entityMap;
enter code here
Then loop through entityMap to get mentioned users:
Object.values(entityMap).map(entity => {
console.log(entity.data.mention);
});

How to use actions.intent.DATETIME?

It is "clearly" defined in the documentation, but I can find no example of how to use actions.intent.DATETIME.
Please provide an example of what is needed in the 'action.json' file, and how my code can get the date and time provided using the assistant SDK helper. I haven't been able to figure out how to use actions.intent.___ at all!
At the simplest level, I want my code to know whether it is morning or evening for the person since I need to give different information in each case. Someone might want to do this to respond "Good morning" or "Good evening".
Also to do with intents, at a more complex level, I also want to know their approximate location (lat/long). I figured that once I know how to work with DATETIME, I'd be able to apply the same code pattern to use getDeviceLocation.
There is some code at https://github.com/actions-on-google/actions-on-google-nodejs that uses the DATETIME intent, but it asks the user for any time. I want to simply know what their current time is.
The DateTime intent can be invoked using the askForDateTime() method from the ActionsSdkApp class in our client library. Simply call the method from an intent, and pass it some queries which clarify the prompting. Then listen for the response using a listener for the actions.intent.DATETIME intent, just as you would listen for the actions.intent.TEXT intent.
In the handler for the actions.intent.DATETIME intent, you can use the getDateTime() method to retrieve the data. Unfortunately this intent only works by asking for an exact date and time from the user, and it is a generic date and time, so there is no guarantee that it is their current datetime unless you structure your prompts in a way to guide the user towards that.
const app = new ActionsSdkApp({ request, response });
function welcomeIntent (app) {
app.askForDateTime('When do you want to come in?',
Which date works best for you?',
'What time of day works best for you?');
}
function datetime (app) {
app.tell({speech: 'Great see you at your appointment!',
displayText: 'Great, we will see you on '
+ app.getDateTime().date.month
+ '/' + app.getDateTime().date.day
+ ' at ' + app.getDateTime().time.hours
+ (app.getDateTime().time.minutes || '')});
}
const actionMap = new Map();
actionMap.set(app.StandardIntents.MAIN, welcomeIntent);
actionMap.set(app.StandardIntents.DATETIME, datetime);
app.handleRequest(actionMap);
As you mentioned you can invoke and handle the actions.intent.PERMISSION intent in a similar way to get a precise longitude and latitude location.
As a side note, if you are using API.AI, you can use their Date and Time system entities to do this, or use the askForDateTime() method in the ApiAiApp class from the client library.
You can em-bed the maps API location/time in your app JSON or, other open source. As far as location it is device and user settings specific so, whether or not you get a JSNODE response from the device/user depends on the user even if they are running the APP and, have different setting preferences.

Is there any way to embed the GitHub Issue Tracker in a webpage?

I'd like to put it in the Progress section of my project's webpage. I tried using an iframe, and I tried using $.load(), but neither of these work.
Any ideas?
If you don't need all the feature from the native GitHub issues page, you could consider listing those issue to generate your own include/presentation.
See "possible to embed Github list of issues (with specific tag) on website?"
Kasper Souren proposes below in the comments the following fiddle:
var urlToGetAllOpenBugs = "https://api.github.com/repos/jquery/jquery/issues?state=open&labels=bug";
$(document).ready(function () {
$.getJSON(urlToGetAllOpenBugs, function (allIssues) {
$("div").append("found " + allIssues.length + " issues</br>");
$.each(allIssues, function (i, issue) {
$("div")
.append("<b>" + issue.number + " - " + issue.title + "</b></br>")
.append("created at: " + issue.created_at + "</br>")
.append(issue.body + "</br></br></br>");
});
});
});
Look at https://github.com/serverless/scope which is based on serverless configuration, uses Amazon DynamoDB framework and github webhook service to fetch issue stats (open, close, comment, labels, milestones, etc.) and pull requests. It's well documented and allows several configurations, including embedding to one's website. I have just tried it and works well so far!

GreenDAO really simple query

I want to create a very simple query to look up a sqlite db using greendao. 2 fields, one is the ID and the other 'affirmation'.
i am sorry to be such a beginner, but i am not sure how to use greendao including what to import etc.. All i have been able to do so far is add the greendao libraries but i cant find a good tutorial to just do a query. Basically i want it to be a random ID that calls up a random affirmation and return it to my main activity.. Once again i am sorry but i am really trying and getting nowhere..
Greendao is a ORM-framework. If you don't know what this means you should look up this first.
Greendao generally works as follows:
You create a java-project that generates your sourcecode for your real app. You have to include DaoCore and DaoGenerator in this project.
You add the generated sourcecode to your android-project and include DaoCore in it. DaoGemerator is not neccessary.
For examples how to generate the code and define your entities the greendao-website is a good place to go.
According to your description you need an entity with id-property and a string-property (affirmation).
In your android-project you then use the DevOpenHelper to get a session and from the session you can get the dao (Data Access Object) for your entity. The dao includes the very basic query to load data by id (load ()).
Please notice that the DevOpenHelper is only meant for development process. For your final release you should extend OpenHelper and costumize your actions to be taken on DB-schema update.
Here is some example code I have in my application.
DaoHelper.getInstance().getDaoSession().clear();
OperationDao dao = DaoHelper.getInstance().getDaoSession().getOperationDao();
String userId = "some id"
WhereCondition wc1 = new WhereCondition.PropertyCondition(OperationDao.Properties.UserId,
" = " + userId);
WhereCondition wc2 = new WhereCondition.PropertyCondition(OperationDao.Properties.Priority,
" > " + 4);
// Uncached is important if your data may have changed recently.
List<Operation> answer = dao.queryBuilder().where(wc1, wc2).listLazyUncached();
This is a decent tutorial on how to learn greendao. Make sure you follow the links to the further parts.
You can use:
daoMaster = new DaoMaster(db);
daoSession = daoMaster.newSession();
yourDao = daoSession.getYourDao();
Random() random = new Random();
List<YourObject> objects = yourDao.loadAll();
YourObject yourObject = objects.get(random.nextInt(objects.size());