I am currently working with the MS chatbot on Azure, using node.js
I am at a point where I need to display a menu for the user, about different choices that may change from time to time.
I get the values through an API call and put them in a tab, then I create the menu and send it to the user. The problem is : I can't create a dynamic menu from my array
This is what I tried :
menu_choices = [x,y,z]
var menu = new builder.Message(session)
.text("This is the menu")
.suggestedActions(
builder.SuggestedActions.create(
session, [ function(){
menu_choices.forEach(function(choice){
builder.CardAction.imBack(session, "I want to select " + choice, choice)
})}
]));
session.send(menu);
It looks strange to use a function inside the SuggestedActions but I don't see how I can solve this, or even if it is possible or not.
Thanks and have a good day !
After working with the Microsoft support, we found the way (well mainly they haha) to do it :
array_Menu = [choice1,choice2,choice3]
var menu = new builder.Message(This is the menu :")
.suggestedActions(
builder.SuggestedActions.create(
session,
array_Menu.map(function(choice) {
return builder.CardAction.imBack(session, "This is a choice : " + choice, choice)
}
)
)
);
session.send(menu);
Related
I am running an influxDb, on my server, and I created below:
Notification Check
Notification Endpoint (HTTP POST)
Notification Rule
All above are running successfuly
I have also created a webhook connector to Microsoft teams in order for InfluxDb send the notification alert to it.
However, for the Microsoft Teams webhook to work successfully, needs a key called "summary" inside request body of the POST request.
InfluxDb has no key called summary in their request body. Something like this:
{
"summary":"text"
}
I am looking to find out how to alter the request body InfluxDb sends, however there is nothing on their documentation.
Any ideas ?
The incoming webhooks send messages as a card. So, the title and summary fields are mandatory. It is by design.
This might be late but I've created my own team connection task in influxdb, where I can add mentions and buttons.
Basic Example:
Copy teams into a task in influxdb and add this next code at the end.
This Example adds a mention for Tom Cruise with its respective teams ID ( use Graph Explorer to get the correct IDs). It's possible to add multiple mentions as follow:
mentions = addMention(name : "James Bond",id:"007") + addMention(name : "Tom Cruise",id:"123456")
Adding Button / Buttons
button = addButton(type: "Action.OpenUrl", title: "Go To Google.com", url:"google.com" )
button2 = addButton(type: "Action.OpenUrl", title: "Go To Mohameds GITHUB", url:"https://github.com/Mohamedkrs" )
url= "https://..."
endpoint1 = endpoint(url: url)
mentions = addMention(name : "James Bond",id:"007")
button = addButton(type: "Action.OpenUrl", title: "Go To Google.com", url:"google.com" )
button2 = addButton(type: "Action.OpenUrl", title: "Go To Mohameds GITHUB", url:"https://github.com/Mohamedkrs" )
crit_statuses =from(bucket: "bucket")
|> range(start: -15s)
|> filter(fn: (r) => r["_measurement"] == "win_cpu")
|> endpoint1(mapFn: (r) => ({
title: "Memory Usage",
text: "<at>team user name</at>: ${r.host}: Process uses ${r._value} GB",
summary: "Alert",
mention: mentions,
button : button + button1
}),
)()
SDK Platform: Node.js
Active Channels: Web Chat
Deployment Environment: Azure Bot Service
Can we create persistent menu button in the typing bar of bot in Node.js?
enter image description here Please refer image: I want to add a menu button in typing bar of bot.
With Bot Framework you are able to use 'suggested actions' as part of your dialog. As the docs show, it produces a menu just above the typing bar. The menu options disappear after the user has made a choice and re-appear again if the user triggers the associated dialog.
Visit this site for a visual sense of the look.
Here is a code sample you can reference. Hope this helps.
Steve.
bot.dialog('/', [
function (session) {
var msg = new builder.Message(session)
.text("Hi! What is your favorite color?")
.suggestedActions(
builder.SuggestedActions.create(
session,[
builder.CardAction.imBack(session, "green", "green"),
builder.CardAction.imBack(session, "blue", "blue"),
builder.CardAction.imBack(session, "red", "red")
]
)
);
builder.Prompts.choice(session, msg, ["green", "blue", "red"]);
},
function(session, results) {
session.send('I like ' + results.response.entity + ' too!');
}
]);
I'd like to have multiple buttons on HeroCard
and be able to press all buttons one after another
but when I press click button program jumps to next function in waterfall
and expects next action instead of button action again
what should I do in this case?
bot.dialog("/showCards", [
(session) => {
const msg = new Message(session)
.textFormat(TextFormat.xml)
.attachmentLayout(AttachmentLayout.carousel)
.attachments([{
title: "title",
url: "https://www.wikipedia.org/portal/wikipedia.org/assets/img/Wikipedia-logo-v2.png"
}].map(obj =>
new HeroCard(session)
.title(obj.title)
.images([
CardImage.create(session, obj.url)
.tap(CardAction.showImage(session, obj.url)),
])
.buttons([
CardAction.openUrl(session, obj.url),
CardAction.imBack(session, `click`, "Click"),
CardAction.imBack(session, `clack`, "Clack")
])
));
Prompts.choice(session, msg, ["click", "clack"]);
},
(session, results) => {
// todo use results.response.entity
}
]);
You could also use CardAction.dialogAction and link every button to a beginDialogAction.
let card = new builder.HeroCard(session)
.title(title)
.subtitle(subtitle)
.buttons([builder.CardAction.dialogAction(session, 'dialogAAction', 'dataYouNeedInDialogA', 'ButtonTitleA'), builder.CardAction.dialogAction(session, 'dialogBAction', 'dataYouNeedInDialogA', 'ButtonTitleB')]);
let msg = new builder.Message(session)
.attachments([card])
session.endDialog(msg);
// use one of these two to either end the dialog and start a new one or to stay in the current dialog and wait for user input
session.send(msg);
// don't forget to add the dialogs to your bot / library later in your code (outside your current dialog)
bot.dialog('dialogA', dialogA); // initialized somewhere in your code
bot.dialog('dialogB', dialogB);
bot.beginDialogAction('dialogAAction', 'dialogA');
bot.beginDialogAction('dialogBAction', 'dialogB', {
onSelectAction: (session, args, next) => {
// you might want to clear the dialogStack if the button is pressed. Otherwise, if the button is pressed multiple times, instances of dialogB are pilled up on the dialog stack.
session.clearDialogStack();
next();
}
});
In my opinion, this is the best way to achieve the behaviour you described so far. All buttons work whenever the user presses them, even if they scroll back in the conversation and press the same button again. The only trade-off is that you have to pass data to the new dialog and can not use dialogData throughout the whole flow. Nevertheless, I think it's worth it because ensures consistent UX throughout the usage of the bot.
Hope this helps. You can build click and clack dialogs, link them to actions and pass the data that you need. The user would be able to press click, clack, click and the bot would still work. :)
Use a switch-case in the ResumeAfter function, in the default case send the user to the previous function.
Is there any way to open a custom screen, as placed in the Acumatica menu in the Site map, as a popup (not a new tab) so that it doesn't occupy the existing browser?
I've tried using this, which works ok:
var url = "http://localhost/AcumaticaDB2562/?ScreenId=AC302000&&OpenSourceName=Bills+and+Adjustments&DataID=" + apinvoice.RefNbr;
throw new PXRedirectToUrlException(url, "Open Source")
{
Mode = PXBaseRedirectException.WindowMode.NewWindow
};
The problem is, I don't want the lefthand menu to show up. I just want the screen without any navigation. Is this possible?
I like to use PXRedirectHelper.TryRedirect for calling other graphs. The WindowMode tells the framework how to open the graph. For your question, you will want to use WindowMode.NewWindow as shown in the example below:
var graph = PXGraph.CreateInstance<MyGraph>();
PXRedirectHelper.TryRedirect(graph, PXRedirectHelper.WindowMode.NewWindow);
The enum values for WindowMode are: InLineWindow, New, NewWindow, PopUp, Same.
Alternatively you could do something like this...
throw new PXRedirectRequiredException(graph, true, string.Empty) { Mode = PXBaseRedirectException.WindowMode.NewWindow };
How can I have 2 conversations going concurrently? I'm currently using TextBot and LuisDialog to build a bot. I start off by having a conversation with the user to obtain data. Then while doing some processing in a different method, I discover that I need additional information from the user. How can I create a new conversation with the user just to get that additional information? I have some code below that attempts to show what I want to do. Thanks for your suggestions.
File 1: foo.js
var dialog = new builder.LuisDialog(model);
var sonnyBot = new builder.TextBot();
sonnyBot.add('/', dialog);
dialog.on('intent_1', [
function(session, args, next) {
name = builder.Prompts.text(session,"What is your name?");
},
function(session, result) {
session.dialogData.name= results.response;
getFamilyTree(session.dialogData.name);
}
]);
File 2: getFamilyTree.js
function getFamilyTree(name) {
find family tree for name
if (need place of birth) {
begin new dialog
prompt user place of birth
get place of birth from user
end dialog
}
finish getting the family tree
}
i guess you could pass session object and then use that object to start a new dialog .
Edit 1
can't you use some thing like
session.beginDialog('/getFamilyTree',{name:result.response});
and then you can access name like
args.name
inside 'getFamilyTree' dialog
I posted the same question on GitHub and received the answer from Steven Ickman, who is involved in the development of the node.js SDK. The link to the answer is https://github.com/Microsoft/BotBuilder/issues/394#issuecomment-223127365