rveachkc / pymsteams

Format messages and post to Microsoft Teams.
https://pypi.org/project/pymsteams/
Apache License 2.0
416 stars 77 forks source link

Enhancement Request - Add Support for @Mentions #11

Open isajediknight opened 6 years ago

isajediknight commented 6 years ago

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 commented 6 years ago

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.

alittlesliceoftom commented 4 years ago

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

jpulidop commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

@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:d6e3fxxxxxxxxxx58xxxxxxxc9dbc1db@thread.skype",
            "name": "The Channel"
          }
        }
      ]
    }
  }
}
rveachkc commented 3 years ago

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 commented 3 years ago

Hi!

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

MathewPazhur commented 3 years ago

Hope this capability is added soon!

tomshaffner commented 2 years ago

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 commented 2 years ago

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

faulander commented 2 years ago

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 commented 2 years ago

Still waiting for this also.

gui1080 commented 2 years ago

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

PahlawanJoey commented 2 years ago

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

MohMehrnia commented 2 years ago

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

elisiariocouto commented 1 year ago

@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 commented 1 year ago

@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:

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 commented 1 year ago

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

elisiariocouto commented 1 year ago

Started the work on #131

GabrielSestieri commented 1 year ago

Started the work on #131

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

LeonardoSanBenitez commented 1 year ago

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": "leonardo.benitez@contorso.com",
                              "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 commented 1 year ago

Hi there,

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

caiolauro commented 11 months ago

I would love to see this feature being released! 😜

lalanatr746 commented 10 months ago

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 commented 7 months ago

@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:d6e3fxxxxxxxxxx58xxxxxxxc9dbc1db@thread.skype",
            "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

dtcMLOps commented 7 months ago

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 commented 1 month ago

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:d6e3fxxxxxxxxxx58xxxxxxxc9dbc1db@thread.skype",
            "name": "The Channel"
          }
        }
      ]
    }
  }
}

Thank you!