Can I create a configuration page for a Teams bot app? - microsoft-teams

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.

Related

How to send message to all the members of the group on Installing teams bot

I have created a teams bot and had a service written in .NET core to handle events and user's messages to reply accordingly.
When I install a bot in a group, I need to send personal message(one-to-one i.e between bot and the user) to all the members of that group on installation. I am trying to do that in OnConversationUpdateActivityAsync event handler (which gets fired when I install the bot). But in this event I am getting information of the user who is installing the bot, not the other members which are added in that group, also I am not getting any information of the channel(channelId and members etc.) in which the bot is getting installed.
Any different approach or solution will work.
Thanks in Advance.
You haven't said if you want the bot to message the users privately (like 1-1 between the bot and user) or just send each person a personal message inside the group chat, but in both cases, Proactive Messaging is your correct approach. If you want to send a message inside the group chat itself, see this sample.
If you want to send the users messages directly, 1-1, they need to have the bot installed as a personal app already. It's possible to do this automatically, but it's a bit more work, and requires Microsoft Graph. The proactive messaging is a bit different too - you get the list of members as per the previous sample, but see here for how to get the required 1-1 conversation details, and how to send the actual message. This last link also has documentation on how to get started, and some background reading (at the bottom of the page).
#Hilton is correct, You need to specify in which scope you want to notify user 1:1 or directly in Group chat?
App should be installed in user scope if notifying user on installation, You can proactively install the App in User/Group Chat/ team scope using Graph API. To notify users in Teams or Group chat, You can fetch the list of members using List conversation members API, When you install the App using Graph API Bot received converstionUpdate, You can save the conversationReference and use it for proactively notifying.

How to get the information about all groupChats in which my bot is part of. MsBot framework for Teams (nodejs)

When someone add my bot to their groupchat I am receiving a ConversationUpdate event and I am storing it for future reference. But storing all conversationUpdate events(which I will get when someone add my bot to their chat) of all groupChats has become a problematic. Is their any function for getting the Information about all groupChats that my bot has added to. Like we have a function for listing all Teams channels ex:- TeamsInfo.getChannels(context)
I would be thankful for any help
I'm not aware of any way to do this - the best I could suggest is something like listing conversation members of existing chats, on the graph beta endpoint (https://learn.microsoft.com/en-us/graph/api/conversationmember-list?view=graph-rest-beta&tabs=http). However, that would mean (a) it needs to returns bots as members of the chat, which I'm not sure it does (b) you'd need to basically query EVERY possible group chat in the organisation and (c) you'd need access rights to do that (e.g. application access). So, it certainly sounds like just storing the conversation id upfront on your own would be a better bet.
Recall that you can get the conversation id (if that's what you're looking for) from any event, not just conversationUpdate - even a regular message to your bot from a user in the chat will have the conversation id attached. Also, you've haven't stated what you need the conversation id for. Presumably it's for pro-active messaging, but in that case remember to store the service url as well.

How to update an existing activity in WebChat

My scenario is: I send card attachments each with an AcceptButton to users. When 1 user clicks on that button, ideally I want to disable all similar buttons (of the same offer) for all users. I am storing conversation details of each user, and I know the ActivityId of each message-with-said-button (it follows a certain string format).
My issue is similar to this and this but for WebChat not Teams.
I did try those solutions but I got the error "Method not allowed" for both UpdateActivityAsync() and DeleteActivityAsync(). Then I read here that UpdateActivity is not supported in WebChat. (But might be available in the future?)
I would like any visual indication that the offer is no longer available. (Right now, they receive an "Offer was already accepted by {UserX}" which would still be in place on top of changing the card/message.)
Is there a way to do this via backChannel? I can trigger an event and pass the ActivityId (tested by showing a simple alert()) but how do I apply changes to that specific activity?
Per this comment in Web Chat's source code and this open issue in the Web Chat repository for adding support for deleteActivity and updateActivity, Update Activity events are not currently supported in Web Chat. Unfortunately, there is currently no way to really update an activity in Web Chat.
Hope this helps!

Need suggestions in getting the conversation details

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.

How do I correlate user between channels?

From what I see, Bot Framework is providing an abstraction over users in different channels by providing a ChannelAccount class that has ChannelId/Address pair to identify user via its account and Id property, which is... okay, here's the question.
I suppose that the idea behind Id is to provide a unique and persistent identifier that can be used to cross-correlate users between account (i.e., I can say that Slack user #alpha is also email user alpha#company.con). This idea is supported by the fact that ChannelAccount for my bot always has same Id regardless of the channel (and Address is different between channels, obviously).
If this is right, and I hope it is, is there any way to provide BotConnector with the correlation information? I.e., I want BotConnector to give me ChannelId/Address, and I'd give back user Id which I'd the get back in incoming message.
The purpose of this is quite simple: I want the code inside my bot to use the Id as already correlated identifier so that I can log it, build logic from it and so on.
BotFramework does not yet support linking of accounts. In the interim, take a look at this post for one way you might implement a solution:
Why isn't BotUserData persisting and retrievable in my Bot Framework bot?

Resources