I'm creating a bot in slack using Microsoft's botframework and LUIS and in Node.js. Currently my bot will reply every time someone says something in the channel, however I want my bot to only reply when its name is mentioned in my slack channel. i.e. #my-bot do this
How would I approach this? Would I have to add slack api in order to do this?
One way I'm thinking is to create an entity to check for if #my-bot is mentioned, and if it is then reply and if not then don't. However, I feel there are better ways in doing this.
Thanks.
Edit:
dialog.onDefault(function (session) {
var msg = new builder.Message(session).entities();
console.log(msg);
console.log(session);
session.endDialog('Default Dialog');
});
I've looked through both msg and session and the Entities of both are empty.
I was able to use session.message.entities to use mentioned to know whenever the bot was mentioned.
Related
I'm trying to code a bot that is able to remove the embed of specific messages or the embed created from the links posted by specific users and bots present in the server.
For example, let's say I don't want to see the twitter embed when someone posts a tweet: my bot would automatically remove the twitter embed.
Other case, I don't want people to see the embed of the messages posted by another user or bot present in the server, my bot would then automatically remove the said embeds.
However, reading the API documentation, I didn't see any possibility to do so. Maybe I missed it or maybe there's a trick to do so. Or maybe it's not supported by the API yet.
So does anyone know how I could achieve that goal please?
PS: Yes, I know I could simply deactivate embeds in the server settings, but that's not the goal I want to achieve here. I want it to be specific to certains links/messages and users/bots.
Thanks
You can use the suppressEmbeds method of message.
client.on("message", message => {
if (message.author.bot) return false;
if (message.author.id !== "YourID") { // Example Condition
message.suppressEmbeds(true) // Removes all embeds from the message.
}
})
I have seen a few bots that have made a bot user
one bot called BetterCensoring did that
It looked like this
does anyone know how to make that?
I have tried to search for an answer a lot but I couldn't find any answers.
Stuff like this is not achieved by actually creating a new user account but rather using a webhook. The send method has the ability to customize username and profile picture of the message.
Webhooks are most easily created with await channel.create_webhook()
Note that a guild can only have 10 webhooks at a time, which is why most bots that use this functionality create a webhook, send a message with it and then delete it right afterwards.
Example (recreating your creeper censoring):
async def on_message(message):
if message.content.startswith('bad word'):
webhook = await message.channel.create_webhook()
await webhook.send('####', username='Creeper', avatar_url='this is an url leading to the creeper image')
await webhook.delete()
I'm using the Microsoft bot-framework to create a bot and integrate it into teams.
Part of the bot's requirements include proactively messaging users once per day. From what I understand, I can only message users that has been added to the team/groupChat after the bot, or that have messaged the bot directly.
My question is - can I somehow bypass this limitation?
A friend of my referred me to a new feature of graphAPI, as part of the new beta version - https://learn.microsoft.com/en-us/graph/api/user-add-teamsappinstallation?view=graph-rest-beta&tabs=http.
To me it doesn't seem like it could be related to the solution since I'm not getting any data back in the response, so if I have no conversationReference object I still can't message the user.
At the moment my solution is to simply broadcast a message in the channel when it's added, asking users to "register" with it by messaging it. Anyone has any other suggestion?
The easiest way is to:
Install the bot for the team
Query the Team Roster -- The link in Step 3 has an alternative way to do this towards the bottom
Create a conversation with the user and send a proactive message
There's a lot of code in those links and it's better to just visit them than to copy/paste it here.
The end of Step 3 also mentions trustServiceUrl, which you may find handy if you run into permissions/auth issues when trying to send a proactive message.
Edit for Node:
Install Necessary Packages
npm i -S npm install botbuilder-teams#4.0.0-beta1 botframework-connector
Note: The #<version> is important!
Prepare the Adapter
In index.js
const teams = require('botbuilder-teams');
adapter.use(new teams.TeamsMiddleware());
Get the Roster
// Get Team Roster
const credentials = new MicrosoftAppCredentials(process.env.MicrosoftAppId, process.env.MicrosoftAppPassword);
const connector = new ConnectorClient(credentials, { baseUri: context.activity.serviceUrl });
const roster = await connector.conversations.getConversationMembers(context.activity.conversation.id);
Send the Proactive Message
const { TeamsContext } = require('botbuilder-teams');
// Send Proactive Message
const teamsCtx = TeamsContext.from(context);
const parameters = {
members: [
roster[0] // Replace with appropriate user
],
channelData: {
tenant: {
id: teamsCtx.tenant.id
}
}
};
const conversationResource = await connector.conversations.createConversation(parameters);
const message = MessageFactory.text('This is a proactive message');
await connector.conversations.sendToConversation(conversationResource.id, message);
Trust the ServiceUrl, as Necessary
Read about it. You'd want this before the message is sent.
MicrosoftAppCredentials.trustServiceUrl(context.activity.serviceUrl);
EDIT: The Graph API you've referenced is only necessary if you wish to proactively message a user who is not in a channel/groupChat where the bot is installed. If you need to proactively message only people who are in context where the bot is installed already, the answer from mdrichardson is the easiest possible method.
We've identified a couple of issues with the Graph API beta endpoint you referenced that should be fixed in the near term. In the meantime workarounds are as follows:
Calling:
POST https://graph.microsoft.com/beta/me/teamwork/installedApps/
{"teamsapp#odata.bind":"https://graph.microsoft.com/beta/appcatalogs/teamsapps/APP-GUID"}
Will install an app in the personal scope of a user.
Known issue: Currently, if the app contains a bot, then installation will not lead to creation of thread between the bot and the user. However to ensure that any missing chat threads, get created, call:
GET https://graph.microsoft.com/beta/me/chats?$filter=installedApps/any(x:x/teamsApp/id eq 'APP-GUID')
Calling:
GET https://graph.microsoft.com/beta/me/chats?$filter=installedApps/any(x:x/teamsApp/id eq 'APP-GUID')
Gets the chat between a user and an app containing a bot.
Known issue: Calling this API will lead to sending a conversation update event to the bot even though there were no updates to the conversation. Your bot will essentially get two install events and you'll need to make sure you don't send the welcome message twice.
We'll also be adding more detailed documentation for the proactive messaging flow using these Graph APIs
I've built a bot using LUIS framework which works fine.
while working on it came through few points as mentioned below
After connecting with LUIS intent; bot is unable to check with regex intents
like
for ex dialog.matches('^helpdesk/i',function()) which i'm trying to setup
var dialog = new builder.IntentDialog({ recognizers: [recognizer] });
How to proactively send greetings message to user before inititates conversation like i would send prompt of choices to user which user can select. If nothing is fitting to that requirement i want LUIS to work and understand on that
How to know the logged in user context in Skype for Business channel
cards are not working in skype for business
For your code; I'm assuming your recognizer is your only IntentRecognizer and is the LUIS model you mention.
In this case, dialog.matches('^helpdesk/i',function()) is incorrect; your code to match against a regex should be dialog.matches(/^helpdesk/i, function())
Alternatively you could add a RegExpRecognizer to your IntentDialog:
var helpdesk = new builder.RegExpRecognizer('HelpDeskIntent', /^helpdesk/i);
var dialog = new builder.IntentDialog({ recognizers: [helpdesk, recognizer] });
As Bob said you're looking for conversationUpdate, here's an example on it sending a message when a user joins
To clarify, is this a question on having your bot know when a user is logged in? Or are you asking about session.userData?
Skype for Business does not currently support cards.
You can catch when the user is added to conversation. Check conversation.update.
Each activity has its own properties. One of them is serviceUrl.
For the third question, please provide your code.
I am testing a bot that I am building using the Bot Framework. The emulator for local testing that Microsoft created has several events that can be provided to the bot to solicit a response.
I looked at the GitHub samples provided for Node.js here, but I can not find any example that responds to the different events within the Bot Framework Emulator.
The states are:
Bot Added to Conversation
Bot Removed from Conversation
User Added to Conversation
User Removed from Conversation
End of Conversation
Ping
Delete User Data
The API also does not make it clear how to achieve any of these actions.
Does anyone have any insight on where I should be looking for a example, or the API entries that I should be using?
In response to one of the answers, I did try code -
.onDefault(function (session) { console.log(session.message.type); }
But it only ever display "message" if a message was sent by the user.
The incoming message.type field will have "BotAddedToConversation" etc.
For the Node SDK, the botConnectorBot is able to trigger custom listeners on events using the on() handler.
Example
var builder = require('botbuilder');
var bot = new builder.BotConnectorBot({ appId: 'APPID', appSecret: 'APPSECRET' });
bot.on('DeleteUserData', function(message) {
// Handle Deleting User Data
});
More information can be found here.
You are also able to configure some standard messages using the configure() method.
Example
bot.configure({
userWelcomeMessage: "Hello... Welcome to the group.",
goodbyeMessage: "Goodbye..."
});
More information on what can be configured through options is located here.
Concerns
This is not part of the question, as the question was to identify how to listen to these events. But as a general concern, the event listener does not return a session object. It is unclear how to act once you handle the event.