-
-
Notifications
You must be signed in to change notification settings - Fork 408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Teams connector #1679
Add Teams connector #1679
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1679 +/- ##
=======================================
Coverage 99.28% 99.29%
=======================================
Files 78 80 +2
Lines 4633 4695 +62
=======================================
+ Hits 4600 4662 +62
Misses 33 33
Continue to review full report at Codecov.
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Is the |
When I tried to implement this connector I've used the webhooks approach and that was still the only way to trigger the webhook. Even the docs say that for you to interact with a bot you need to @ it so it must be a design choice |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool. I just went surfing through the docs to see if I could find anything helpful. Here is what I found.
teams_channel_id = self.parse_channel_id(message.target) | ||
try: | ||
connector_client = await self.adapter.create_connector_client( | ||
self.service_endpoints[teams_channel_id] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. I wonder if there's another API we could use to get the list of users (and therefore endpoints) in a channel...
botbuilder.core.teams.teams_get_team_info
looks promising. It returns a TeamInfo
object with methods like get_team_details
, get_team_channels
, and get_team_members
. I wonder if that could be used to generate a list of service_endpoints.
https://docs.microsoft.com/en-us/python/api/botbuilder-core/botbuilder.core.teams.teamsinfo?view=botbuilder-py-latest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another possibility to allow sending messages to channels is to use "incoming webhooks": https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook
Sending cards requires using "the actionable message card format".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe Proactive messaging could also be used to allow sending messages.
Here's an interesting quote:
you can use the Microsoft Graph API to proactively install your bot for your users
And a key piece:
When your app is installed for the user, the bot will receive a
conversationUpdate
event notification that will contain the necessary information to send the proactive message.
Which would provide all those service endpoints.
Reference docs for how to do this in an app:
https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/send-proactive-messages?tabs=python
from botbuilder.core import ( | ||
BotFrameworkAdapterSettings, | ||
BotFrameworkAdapter, | ||
MessageFactory, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
core.CardFactory
might be helpful in addition to MessageFactory
Here's the relevant bit about
|
Co-authored-by: Jacob Floyd <[email protected]>
OOH! look what I found: So, if we step outside of the BotFramework supported APIs and use the graph API, it looks like the bot COULD subscribe to all messages in a channel by subscribing to To use this, there are additional "protected API" restrictions: https://docs.microsoft.com/en-us/graph/teams-protected-apis which means everyone (ie every teams admin adding OpsDroid to their teams tenant(s)) would have to apply for access to use the API for their OpsDroid teams-app in their tenant with https://aka.ms/teamsgraph/requestaccess. |
Interesting. It seems strange that you are required to request additional permissions via some web form that is reviewed by a human. Sounds like it could be inconsistent. I wonder what the criteria are for approving these? I'm not saying we shouldn't do it. But it should probably be in addition to the regular bot APIs. |
Found out why the tests are freezing. Pip is endlessly backtracking. This is the culprit: botframework-connector specifies I didn't notice this locally because I have an old version of pip installed so I wasn't using the new pip resolver. |
8dc26ff
to
40a9204
Compare
It is stripping "/" from the end of URLs now probably due to: matrix-nio/matrix-nio@574a2ee But, it looks like that was their intention all along, so this is a bugfix. This adjusts our tests to not expect the final "/" anymore.
stale bot: You're wrong. |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I hope the feature will be integrated. |
I wonder if there are any hooks we can use to control uuid generation in the teams lib. Maybe a fixture that makes |
Possibly! I'd rather avoid digging too deep into the teams SDK. I was thinking about trying to write a custom VCR handler which stripped the uuid. But patching |
Found the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow. 😥
Looking at the coverage, I think adding a bit to the test will test the rest of the significant code.
Also, I'm not sure what the docker/pip test failure is about.
@cognifloyd you've been great at reviewing here. Do you want to give this a last pass and hit the big green button? |
@FabioRosado and I started working on a Teams connector today.
Things are functional, the bot can receive messages and respond.
Teams is a little weird because the bot has to be @ mentioned in every message in order for it to process it. And to send notification messages to a room the user has to have spoken to the bot in that room at least once. Other than that things are pretty standard.