Need suggestions in getting the conversation details - botframework

I am creating a bot using MS Bot framework - NodeJs. The below information needs to be captured for logging (Using the bot.use method i.e. IMiddleware).
Receive:
a. UserId
b. UserInput (text)
c. ConversationId
Send:
1. Name of Intent or dialog name that handled this (that handled the user input text)
2. Bot output text
3. ConversationId
4. UserId
I am unable to get the required detail for the 'send'. Can anyone provide me some suggestions on this.
Thanks.

I believe your main struggle is to log the name of intent or dialog. You won't know it in your send middleware if you haven't captured it during the routing phase. Once the Bot Framework figured out where to send the incoming message, it just invokes that function.
These two articles may help you get what you want. Just recently I played with capturing the conversation's breadcrumbs and also logging a full transcript:
http://www.pveller.com/smarter-conversations-part-3-breadcrumbs/
http://www.pveller.com/smarter-conversations-part-4-transcript/
If you need to build a reliable capture engine, I would suggest that you didn't use the session.privateConversationData like I did and instead built your own storage/log infrastructure to push the events to. Just stream them out with a timestamp and conversationId and reconcile on the other end later. The asynchronous nature of everything the bot framework does internally will be haunting you along the way so that's why. Plus, once you scale out beyond testing on a few users and your bot spans multiple processes, you will be out of the single-threaded event loop.

Related

Can I create a configuration page for a Teams bot app?

I'm building my first Teams app which will have two primary functions:
Proactively send a message to the channel (the bot is installed into) when a specific event occurs on my backend.
Members of the channel reacts to the message via actions.
I finally have a pretty good idea of how to set this up (I think) - but one part I'm missing is that in order to identify the specific app installation as belonging to one of my customers, I need to be able to allow the installing user to supply extra information like e.g. an API-key so that I can associate the specific channel with my specific customer.
Is there any way of doing this with a bot app? I've found examples for creating a configuration page, but they all seem to be associated with tab apps?
I could of cource have the bot ask the user for the information - but maybe there's a "cleaner" way?
Any examples or tutorials would be greatly appreciated as I find it rather hard to get stuff working using Microsoft's own examples etc. :)
Thanks a lot!
When you receive any message from the user, either by typing to your bot, or even installing it into a channel, group chat, or personal context (where you get the conversationUpdate event), you are able to get specific details off of the activity object. If the user sends a message, for instance, then the text property on the activity object will have a value. Incidentally, this is the same activity you will use to get the conversation details you need for the Proactive message.
With regards your question, the activity class also includes a tenantId property, hanging off the conversation property. This is the unique Microsoft 365 Id for the tenant, which would be what I'd suggest to uniquely identify them for your API, or licensing, or similar.

Slack API - persistent message visible only to a set of users in a public channel

I'm planning to write a slack app, and I need to render messages depending on who read them.
I'm thinking something like: the App should have some options, and user's clients should render the messages depending on the options chosen by the user.
Is there a way to post a persistent message (I mean not an ephemeral message) which is shown only to a user (or a set of users)?
Or
Is it possible to post a message shown differently depending on the user who read it?
I don't need to send private or sensitive data, so if the solution to my problem is a message containing all the content for all the users in the channel, it is perfectly fine. It's just matter of user experience.
I have two constraints:
The user experience for those who don't use the App should not be impacted
I need the messages from the App to be rendered in reply to messages sent by the users, so solutions like "open a new channel" or "send direct messages" are not suitable for my needs.
Thank you all (but the Slack team which, in case let us doing that, it makes that not clear in the documentation :D )
This is not possible unless you create your own client to show/display the messages.
Custom slack apps usually augment to the existing functionality. How do you expect to override the functionality of Native Slack 'Desktop, Mobile & Web' Client.
I am happy to discuss this further, if you have some approach in mind.

How do I notify users on Slack that aren't in the channel?

What we are trying to do
I am working on automation which posts messages to a Slack channel using Incoming Webhooks on a custom Slack App. The messages mentions people.
What works
We can send a message just fine, it has formatted content, and usernames are correctly resolved using the link-names flag.
What isn't working
The whole point of the notification is to inform a dynamic set of people about something they should care about. The set of people we tag varies hugely (think people who contributed to a pull request) and so not all possible recipients are in the channel these automated messages go to.
We assumed that given the usernames are being directly #-mentioned, they would be notified by Slack. However, two of the users we've tested with and #-mentioned confirm they never received a notification they had been tagged.
This is different to "human" behaviour, where if you #-mention someone in Slack, you get a little message reminding you that person isn't in this channel and offers to invite them or let them know.
As far as we can tell, sending the message programmatically is doing the equivalent of "Do nothing" in the picture above. I want to do either of the other two options, preferably "Let them know".
How can I notify people they've been mentioned? I've looked at all the API documentation and nothing discusses notifying users who aren't in the channel that they are mentioned.
This can't be an uncommon issue.... right?
Notes:
We aren't directly calling chat.postMessage, it's just the only documentation on link_names I could find to link to. We are using Incoming Webhooks, which has minimal documentation on the parameters - it seems to be the same as chat.postMessage.
We would prefer not to move off Incoming Webhooks, but we can do a custom integration with the API if we have to.
You need to invite the user to the channel first, using the Python client that's:
client.channels_invite(
channel=channel_id,
user=user_id
)

Conversation in Microsoft Teams

We need to automate few notifications from our web application. These get triggered at various phases, for eg. Step A, B or C would trigger emails to specific parties.
AS an improvisation to this, teams integration is being looked at where a specific channel is being created and with webhook, the messages can be posted.
I created a custom channel with an incoming webhook and I posted a JSON request (of type #messagecard) which was viewable in the channel. But the need is to really establish a conversation and not separate individual messages. By conversation, we mean a scenario or tree structure like below
OverAll status 1 (Parent message)
--> subsequent reply (child message)
---> subsequent reply (child message)
I did some R&D and found that the incoming webhook post request does not return any message id (thsi feature doesnt exist)
What I do not understand is how bots (Azure or Microsoft) can help here.
Please advise
Webhooks/connectors is perfectly fine for the single messages, are you're seeing, but I don't think it will give you the ability to create and then continue an existing "conversation" (i.e. a thread). You certainly could achieve something like this using a "bot"-based approach. In practice, it's kind of "bot+extra" because you need two things:
1) A bot registered into the channel. This will give you some key info you need to be able to send messages from outside Teams - something called a "proactive" message. Having the bot in the channel also means you have something with the authorization to send a message to the channel
2) Next you need to implement the Proactive message. Have a look at my answer here to see more: Programmatically sending a message to a bot in Microsoft Teams (the answer is in C# - not sure what language/platform you're using, but the same concepts apply in Node)
In addition to the pro-active message, once you send that first message, you need to store the message reference that comes back from "SendToConversationAsync". You then apply it to the subsequent messages, as I've described in the answer here: How to add a mention in Teams alongside an adaptive card using Bot Framework
Hope that helps

Creating a Slackbot that adds

Hey in my team's slack (messaging system for those who don't know) we have an automatic response, so that when anyone says "trump", slackbot automatically responds with "the wall just got ten feet higher". Now I want to make a counter that essentially allows slackbot to state "the wall just got ten feet higher, wall height:(have a updated value according to number of times "trump" has been stated)" So basically I want a way to have a value that updates the wall height but I am lost on how to do that within slackbot. Any help is much appreciated, thanks to all!
The default features provided by Slackbot only allows it to respond to keywords, but not much more. So to provide that additional feature you would need to develop a custom bot.
For your use case I would recommend building a so called internal integration for Slack using the Events API.
Internal integration allows you to add custom functions for your Slack team only (as opposed to a full fledged Slack app, that could also be installed and used for other Slack teams).
The Events API allows you to set up a bot that listens to messages and can react to keywords like "trump".
An alternative approach to the events API would be the outgoing webhook. However this function is now deprecated and should no longer be used. Also it only works with public channels.
To set this up you will need to develop a small webservice (e.g. in PHP) that listens on a webserver for requests from the events API, keeps count of how many times the keyword has been invoked in the past and sends an appropriate message back to your Slack team every time the keyword is used.
I can recommend reading the excellent official Slack API documentation if you want to learn more.
If you are familiar with PHP this can be done easily using the Slackbot Framework. It supports Events API allowing you to listen to messages in channels or direct messages (depending on the permission scopes of your APP). So all the conversations on Slack can be sent to your server and you can search for the specific keyword in every message. Then send back an appropriate message to Slack. In summary, the first step is to create an APP for your slack team at https://api.slack.com/apps?new_app=1. Next step is to install the Slackbot Framework which is explained here. Hope this is helpful.
That can also be done by integrating custom slack bot using Django. You'll have to subscribe events and based on events, Slack will send conversation message to the given url, and based on the event, you can write your logic to increase count and post message back to slack work space.

Resources