'reloadAction' in Microsoft Bot Framework 3.15 for Node.js is not passing on 'dialogArgs' - node.js

I'm following the example from the Bot Framework pages, under 'Handle User Actions' (https://learn.microsoft.com/en-us/azure/bot-service/nodejs/bot-builder-nodejs-dialog-actions?view=azure-bot-service-3.0)
// Order dinner.
bot.dialog('orderDinner', [
function(session, args, next){
if(args && args.isReloaded){
// Reload action was triggered.
}
session.send("Lets order some dinner!");
builder.Prompts.choice(session, "Dinner menu:", dinnerMenu);
}
//...other waterfall steps...
])
// Once triggered, will restart the dialog.
.reloadAction('startOver', 'Ok, starting over.', {
matches: /^start over$/i,
dialogArgs: {
isReloaded: true;
}
});
and after reloading the dialog args.isReloadedis always undefined. That is, it doesn't seem that the framework is passing through what is put in dialogArgs. Any clues as to what I might be missing? I'm using v 3.15 (or rather, the people for whom I'm working are using 3.15) -- was this something that was introduced in a later version 3, that is, after 3.5? Or is something just going wrong?
Any help much appreciated!

Tried the code with the specified version and is working correctly. There is an errant ";" in your code (which is also in the docs) that should be removed and may be the culprit. Change the following line to the below.
Hope of help!
dialogArgs: {
isReloaded: true
}

Related

Chrome extension declarativeNetRequest: get notified on request blocked

The new manifest version 3 of Chrome extension API offers a new function setExtensionActionOptions which allows a typical content blocker to display the number of blocked HTTP requests for a particular tab. The question is: when to call this API? How do I get notified that a request was just blocked and I need to call it with "increment: 1"? I'm looking for the event "onRequestBlocked" or some workaround.
The alarm API is no good because it fires once per minute. Ideally, I'd like to have this number updated in real time, as it is possible with the old MV2.
Another potential solution is to keep the service worker always running which kind of defeats the fruit of moving to MV3 at all.
There's no way to get notification outside of debugging in unpacked mode via onRuleMatchedDebug event.
You can enable automatic display of the number of the blocked requests on the icon badge.
For example, do it when the extension is installed/updated:
chrome.runtime.onInstalled.addListener(() => {
chrome.declarativeNetRequest.setExtensionActionOptions({
displayActionCountAsBadgeText: true,
});
});
You can also provide an explicit increment using tabUpdate property at any time you want:
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
if (msg.type === 'block') {
chrome.declarativeNetRequest.setExtensionActionOptions({
tabUpdate: {
tabId: sender.tab.id,
increment: msg.count, // Negative values will decrement the count
},
});
}
});
For future seekers: I've been able to find the following solution
chrome.webRequest.onErrorOccurred.addListener(
(details) => {
chrome.declarativeNetRequest.setExtensionActionOptions({
tabUpdate: {
tabId: details.tabId,
increment: 0
}
});
},
{
urls: ["<all_urls>"]
}
);
Yes, this also counts requests that are blocked by other extensions, but in practice I believe this is not so much of a problem. Another thing that's hard for me to explain, is this increment: 0 parameter. For some reason, the action count is actually incremented by increment + 1, not increment when the tabUpdate argument is provided. So, bizarre enough but works for me quite well this far.

how to move to other section in script

I'm building a bot using gupshup.io using the scripting way ... but handling some things in default.js file as mentioned in the docs
I'm trying in a handler function to check if the event.message equals specific string to go to another section in the script
can anybody please help ?
thanks a lot
So to achieve that you can create a child state to go another section and just set options.next_state to that state. I mean suppose you have a script like this
[main]
inputParser:Welcome to New Bot.
thisFlow:
This is a output of this flow.
callAnotherFlow:
:call default.anotherFlow
[anotherFlow]
This is another flow.[[Wow, No]]
Wow
Thanks
No
Oh!
So in case if the message is 'another flow' you want the second flow to begin. So in the input parser you can create something like.
module.exports.main = {
inputParser: (options, event, context, callback)=>{
if(event.message.toLowerCase() === "another flow"){
options.next_state = 'callAnotherFlow';
}else{
options.next_state = 'thisFlow';
}
callback(options, event, context);
}
}
I think this is what you are looking for.

Ending conversation

My bot (using MS BotFramework) is supposed to be hearing the conversation stream. If someone mentions 'chatbot' it should say 'Here I am!', otherwise stays quiet. It seems to be very simple and maybe it is but I am having a hard time trying to implementing it. Here is what I have:
bot.add('/', function(session) {
if (someoneSaidChatbot) {
session('Here I am!")
} else {
// session.reset(), maybe? No!
// session.endDialog() then? Uh...nope.
// nothing? Hmmm. negative
}
});
So, nothing works. If I leave there the bot just hangs and it stops listening to the stream or answering commands.
Any thoughts?
This code ends a dialog when someone types "chatbot" as part of the utterance. Is this what you are looking for?
bot.add('/', function (session) {
if (session.message.text.search("chatbot") >= 0) {
session.endDialog("Here I am");
}
});
I'd like to suggest use endConversationAction() to register a Bots Global Actions
bot.endConversationAction(
'enddialog', //dialog Id
'Here I am', //message
{ matches: /^.*chatbot/i } //match pattern
);
since this is global action, anytime when bot heard "Chatbot", it will say "Here I am" , if there are some dialog in stack, your proposed solution might not work.
It may also depend on which channel you're using. Some channels don't offer the ability for the Bot to listen to all of the messages in the conversation.

visual-studio-code: Howto executeCommand<T>(command: string, ...rest: any[]): Thenable<T>

I try to figure out how to implement a visual studio code extension. (Based on the "Hello World!" example.)
I want to do the following:
Execute an example.cmd file in the editor in a node.js child_process (that works)
But prior to that, automatically save the file to activate the latest changes (thats the problem)
At https://code.visualstudio.com/Docs/extensionAPI/vscode-api there is description of visual studio code api.
This is the command I think to be used:
executeCommand<T>(command: string, ...rest: any[]): Thenable<T>
What I need:
The file save is asynchronous. E.g. there may show up a File Save Dialog. The user may save properly or cancel it. I need to wait til end of the user action, then in case of succeess call my command prompt.
In my code:
let disposable = vscode.commands.registerCommand('extension.sayHello', () => {
....
var retval =
vscode.commands.executeCommand('workbench.action.files.save')
.then(function(result)
{
// It should wait til end of user action,
// But it never reach here
myOutputChannel.append('workbench.action.files.save:' + result + '\n');
});
// and immediately runs the child process code below
....
});
What happens:
It runs through the code, don't wait, don't save, process the non existing file, reports an error, exit function. After all the File Save Dialog appears. :(
Can anyone give me a hint whats wrong? Is this a bug of visual studio code? Or what I am doing wrong? I am new to node.js . I guess, I didn't get how to use Thenable<T> properly?
Here's a short snippet on how to properly save the file:
let editor = vscode.window.activeTextEditor;
if (!editor) {
return;
}
let doc = editor.document;
await editor.document.save();

Chrome extension delay condition

I have created a chrome extension which does something after its button is clicked.
However I dont want it be abused so I need the its code to be executed after some time.
How can I surround this code with a timeout in order to achieve this?
Thank you for reading me!
chrome.tabs.getSelected(null,function(tab) {
var Mp=tab.url.substring(0,23);
if(Mp=='https://www.example.com')
{
onWindowLoad();
chrome.extension.onMessage.addListener(function(request, sender) {
if (request.action == "getSource")
{
...Working here
}
});
}
else
{
message.innerHTML='<span style="color: #f00">This is not a valid page</span>';
}
});
function onWindowLoad()
{
var message = document.querySelector('#message');
chrome.tabs.executeScript(null, {file: "getPagesSource.js"});
}
I had to make a compromise so just after the getSelected I added the following line:
chrome.browserAction.disable(tab.Id);
It disables the action button thus it cant be clicked while the script sends the data to the server, as with this extension I grab the tab url in order to store it in my database.
After the ajax response and adding the following
if(xhr.readyState==4)
{
message.innerHTML=xhr.responseText;
chrome.browserAction.enable(tab.Id); /////<---THAT LINE
}
the button gets ready again to be clicked.
I couldnt find the way to add a specific delay in seconds, this way seems stupid but its working, as the response's delay from my server is enough for switching the 2 states of the action button.
With this, however another problem came up, which Ill write in different question.

Resources