Skip to content
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

Enhancement Request - Add Support for @Mentions #11

Open
isajediknight opened this issue Mar 19, 2018 · 28 comments
Open

Enhancement Request - Add Support for @Mentions #11

isajediknight opened this issue Mar 19, 2018 · 28 comments

Comments

@isajediknight
Copy link

This code really makes it easy for us to integrate automated communications into our Teams Channels.

I would like to request @mentions be supported. We have various scenarios when we would like to tag/notify Associates of events. Supporting an @username tag/notification would really help us take Microsoft Teams to the next level.

@rveachkc let me know if this is not the Official Microsoft Repository for Teams. If it isn't I'll repost this request there.

@rveachkc
Copy link
Owner

Mentions are currently not supported for incoming webhooks: https://techcommunity.microsoft.com/t5/Microsoft-Teams/Microsoft-Teams-Incoming-Webhook-Message-Formatting/td-p/31984

This is not an official Microsoft repo, but it is functionality that I've looked into as well. I'll keep this open for tracking purposes. Hopefully, it can be added later.

@rveachkc rveachkc added the No API Support Feature requests that are not supported by the Microsoft API label Mar 19, 2018
@alittlesliceoftom
Copy link

Microsoft have had open requests for this for 4 years. Not holding my breath!
Thanks for a great lib :)

@jpulidop
Copy link

Currently we are using this excellent library for monitoring our ETLs in Teams but we would like to use mentions as well.

It would be a great feature!

Thank you!

@Josverl
Copy link

Josverl commented Sep 2, 2020

At-mention support is now avaialble using adaptive cards with AC v1.2 in Teams.
Please refer to :

and it is now possible to send an AC to a Teams Channel webhook by specifying it as an attachment to the message.

@alj032
Copy link

alj032 commented Sep 3, 2020

At-mention support is now avaialble using adaptive cards with AC v1.2 in Teams.
Please refer to :

and it is now possible to send an AC to a Teams Channel webhook by specifying it as an attachment to the message.

@Josverl Does this mean it is now possible to mention channels with pymsteams?

I don't see anything about adding an attachment on their documentation and I have tried sending it through the text section.

myTeamsMessage = pymsteams.connectorcard("")
myMessageSection = pymsteams.cardsection()
myMessageSection.title("Your phone ringing")
myMessageSection.text("<at>Area 51</at>")

myTeamsMessage.addSection(myMessageSection)
myTeamsMessage.text("Message")
# send the message.
myTeamsMessage.send()
print('Message Sent')
time.sleep(90)`

@Josverl
Copy link

Josverl commented Sep 4, 2020

@alj032
AC to Connector:
you need to specify the card as an attachment to the message ( as this is the way Teams does it internally)

{
   "type":"message",
   "attachments":[
      {
         "contentType":"application/vnd.microsoft.card.adaptive",
         "contentUrl":null,
         "content":{
            "$schema":"http://adaptivecards.io/schemas/adaptive-card.json",
            "type":"AdaptiveCard",
            "version":"1.2",
            "body":[
               {
                  "For Samples and Templates, see":"https://adaptivecards.io/samples"
               }
            ]
         }
      }
   ]
}

Ref : https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using#send-adaptive-cards-using-an-incoming-webhook

Channel Mention:
good question , I don't know . its not specified but I would suggest you give it a try by specifying the channelId in stead of the userId

username in the supported adaptive card elements
The mention object inside of an msteams property in the card content, which includes the Teams user id of the user being mentioned

but perhaps we can extend that logic :

below is untested : (and would need to be wrapped as an attachment per above)

{
  "contentType": "application/vnd.microsoft.card.adaptive",
  "content": {
    "type": "AdaptiveCard",
    "body": [
      {
        "type": "TextBlock",
        "text": "Hi <at>Channel</at>"
      }
    ],
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.0",
    "msteams": {
      "entities": [
        {
          "type": "mention",
          "text": "<at>Channel</at>",
          "mentioned": {
            "id": "19:[email protected]",
            "name": "The Channel"
          }
        }
      ]
    }
  }
}

@rveachkc rveachkc added help wanted and removed No API Support Feature requests that are not supported by the Microsoft API labels Sep 4, 2020
@rveachkc
Copy link
Owner

rveachkc commented Sep 4, 2020

hey all, thanks for the interest. It's going to be a bit before I can work on this, but pull requests are always welcome.

@magnuslu
Copy link

Hi!

I'm also looking forward to this capability to be included.

@MathewPazhur
Copy link

Hope this capability is added soon!

@tomshaffner
Copy link

tomshaffner commented Sep 29, 2021

hey all, thanks for the interest. It's going to be a bit before I can work on this, but pull requests are always welcome.

If someone were to start development on a pull request for this, recommendations on where they should begin looking to accomplish this faster? Based on the Microsoft link above I'd think maybe it needs two parts; one to look up an ID and a second to mention that ID? Thoughts on where/how they should fit into the structure you already have here?

@jerryeml
Copy link

any update!?
Mention function is really helpful for us if available!!!
Many thanks

@faulander
Copy link

I am also looking forward to this. if i get a heads up where to start implementing, i can submit a pull request aswell.

@cassiobolba
Copy link

Still waiting for this also.

@gui1080
Copy link

gui1080 commented May 9, 2022

Hello, also looking foward to this upgrade! Would be extremly helpful atm.

@PahlawanJoey
Copy link

I'm also looking forward to this! Would be a great help!

1 similar comment
@MohMehrnia
Copy link

I'm also looking forward to this! Would be a great help!

@elisiariocouto
Copy link

elisiariocouto commented Aug 16, 2022

@rveachkc
First of all, thank you for this package. It helped me a lot in the past months. I started reading about Adaptive Cards for the mention feature, and I was able to post some messages via requests. I would like to add Adaptive Cards support on this project and, with this, I would also add the mention capability. Since this is kind of a major refactor, I would like to add support for more modern Python tools like pyproject.toml, black formatting, etc. Are you open to this refactor?

@rveachkc
Copy link
Owner

@elisiariocouto, apologies for the delay - life is busy.....

I agree that a major refactor is needed. I've started playing around with it in https://github.com/rveachkc/pymsteams/tree/adaptive-cards, but haven't gotten past the chores part of it. To be 100% transparent, I just haven't had the motivation to do it in the spring/summer/fall months. I typically dive into projects like this in the winter.

A few of the things I'd like to do with the new branch:

  • black formatted - this is already done in my editor, but could use to be added to a CI/CD job.
  • use another library to provide adaptive card formatting. I would rather not support it than have a half-baked implementation. There aren't enough pymsteams contributors to support this, so I've bookmarked pyadaptivecards as a strong candidate for reasons discussed in Created Adaptive card function and also mention user is available on this card #118. I'm open to suggestions though.
  • Test cleanup - previous tests actually sent messages to channels defined in environment variables. This has been where I've spent the majority of my uplift efforts. Async testing is hard.....
  • github actions migration - Current CI/CD jobs run on the free tier of CircleCI. It's a fantastic tool, but I feel that using GitHub Actions would make the project more cohesive, plus, I'd like some exposure to it. This would not be an absolute blocker.
  • General modernization: drop python2 support, type hinting, sphynx docs, etc

I don't know a whole lot about pyproject.toml, but I'm open to it as long as it can be adapted to use the same version check logic my current setup.py provides. The PyPI release is automated as well.

@elisiariocouto
Copy link

I agree with all of this. Will start working on this soon :)

@elisiariocouto
Copy link

Started the work on #131

@GabrielSestieri
Copy link

Started the work on #131

Hey Elisiario! Love seeing this. Any updates on mentioning a user using the module?

@LeonardoSanBenitez
Copy link

LeonardoSanBenitez commented Oct 9, 2022

While this is not implemented, this is a temporary solution that works:

teams_message = pymsteams.connectorcard(webhook)
teams_message.payload = {
    "type": "message",
    "attachments": [
        {
        "contentType": "application/vnd.microsoft.card.adaptive",
        "content": {
            "type": "AdaptiveCard",
            "body": [
                {
                    "type": "TextBlock",
                    "text": "Hello <at>Leonardo</at>"
                }
            ],
            "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
            "version": "1.0",
            "msteams": {
                "entities": [
                    {
                        "type": "mention",
                        "text": "<at>Leonardo</at>",
                        "mentioned": {
                              "id": "[email protected]",
                              "name": "Leonardo Benitez"
                        }
                    }
                ]
            }
        }
    }]
}
teams_message.send()

Source: https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format?tabs=adaptive-md%2Cconnector-html#user-mention-in-incoming-webhook-with-adaptive-cards

@PaulSec
Copy link

PaulSec commented Jun 21, 2023

Hi there,

First of, thanks for the work!
I was wondering if you had some news regarding that issue? Cheers!

@caiolauro
Copy link

I would love to see this feature being released! 😜

@lalanatr746
Copy link

Is there any way we can include something similar to @mention within a MessageCard type instead of adaptive card. I heard that @mention is not supported by MessageCard. Has anyone figured out a way to mention team members in MessageCard structure? Please, do let me know

@thebruuu
Copy link

thebruuu commented Nov 17, 2023

@alj032 AC to Connector: you need to specify the card as an attachment to the message ( as this is the way Teams does it internally)

{
   "type":"message",
   "attachments":[
      {
         "contentType":"application/vnd.microsoft.card.adaptive",
         "contentUrl":null,
         "content":{
            "$schema":"http://adaptivecards.io/schemas/adaptive-card.json",
            "type":"AdaptiveCard",
            "version":"1.2",
            "body":[
               {
                  "For Samples and Templates, see":"https://adaptivecards.io/samples"
               }
            ]
         }
      }
   ]
}

Ref : https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using#send-adaptive-cards-using-an-incoming-webhook

Channel Mention: good question , I don't know . its not specified but I would suggest you give it a try by specifying the channelId in stead of the userId

username in the supported adaptive card elements The mention object inside of an msteams property in the card content, which includes the Teams user id of the user being mentioned but perhaps we can extend that logic :

below is untested : (and would need to be wrapped as an attachment per above)

{
  "contentType": "application/vnd.microsoft.card.adaptive",
  "content": {
    "type": "AdaptiveCard",
    "body": [
      {
        "type": "TextBlock",
        "text": "Hi <at>Channel</at>"
      }
    ],
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.0",
    "msteams": {
      "entities": [
        {
          "type": "mention",
          "text": "<at>Channel</at>",
          "mentioned": {
            "id": "19:[email protected]",
            "name": "The Channel"
          }
        }
      ]
    }
  }
}

Lookgin forward for implementation as I manage to make this code work for ppls but not for Channels :(
Probably issue on recovering correct id of Channel ...but used https://developer.microsoft.com/en-us/graph/graph-explorer

@codebydant
Copy link

codebydant commented Dec 4, 2023

Hi folks, is there an example using pymsteams.cardsection()? I need to provide a report with a couple of mentions and the workaround creates another card with no information about the event. Any help would be appreciated

image

@cedoard
Copy link

cedoard commented Jun 4, 2024

Hello everyone! Has anyone figured out how to integrate mentions in a section without having to send a new message solely for the user mention?

Let me clarify. This is the payload of the message I created with pymteams:

{ 'title': 'value',
  'text': 'value',
  'sections': [{'title': "value",
                 'activityText': 'value'},
                   {'title': "value",
                    'activityText': 'value'},
                   {'title': "value",
                   'activityText': 'value'}
  ],
 'potentialAction': [{'@context': 'http://schema.org',
   '@type': 'ViewAction',
   'name': 'ExampleAction',
   'target': "www.example.com"}],
 'themeColor': 'eedc00'}

How can I add the following mention to the previous payload? Is the only way to create another message?

 {"contentType": "application/vnd.microsoft.card.adaptive",
 "content": {
   "type": "AdaptiveCard",
   "body": [
     {
       "type": "TextBlock",
       "text": "Hi <at>Channel</at>"
     }
   ],
   "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
   "version": "1.0",
   "msteams": {
     "entities": [
       {
         "type": "mention",
         "text": "<at>Channel</at>",
         "mentioned": {
           "id": "19:[email protected]",
           "name": "The Channel"
         }
       }
     ]
   }
 }
}

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests