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

How to use @mention #127

Closed
fc-ds opened this issue Oct 25, 2021 · 9 comments
Closed

How to use @mention #127

fc-ds opened this issue Oct 25, 2021 · 9 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@fc-ds
Copy link

fc-ds commented Oct 25, 2021

Hello,

I'm trying to mention someone in the cards like I do manually with @user .

Is there a way to do that with this lib ?

@atc0005
Copy link
Owner

atc0005 commented Oct 25, 2021

@fc-ds I do not believe that mentioning someone via incoming webhooks is permitted by Microsoft Teams. At least, it wasn't when I last looked into the support for it.

I don't have the original references I looked at available to cite, but I specifically recall looking into this in the past and found it wasn't an option.

If you find that this is now supported via Incoming Webhooks, please share those details so we can look further into it. It would be useful to have that support in this library.

@atc0005 atc0005 added help wanted Extra attention is needed question Further information is requested labels Nov 12, 2021
@ghokun
Copy link

ghokun commented Jan 18, 2022

You can mention someone with following:

curl -X POST -H "Content-type: application/json" -d '{
    "type": "message", 
    "text": "Hey <at>Some User</at> check out this message",
    "entities": [
        {
            "type":"mention",
            "mentioned":{
                "id":"some.user@company.com",
                "name":"Some User"
            },
            "text": "<at>Some User</at>"
        }
    ]
}' <webhook_url>

@atc0005
Copy link
Owner

atc0005 commented Jan 21, 2022

@ghokun thanks for sharing!

@atc0005 atc0005 added enhancement New feature or request and removed question Further information is requested labels Jan 27, 2022
@atc0005
Copy link
Owner

atc0005 commented Jan 27, 2022

@fc-ds Thanks to the feedback from @ghokun, we now know that this (much requested) feature is available in Microsoft Teams.

I'll first prototype the support in a small project that I maintain which uses this library, then land the applicable changes here. No estimates for when that will be, but I'll be sure to let you know when it does.

Thanks for opening this issue and your interest.

@atc0005
Copy link
Owner

atc0005 commented Jan 28, 2022

@ghokun: You can mention someone with following:

curl -X POST -H "Content-type: application/json" -d '{
    "type": "message", 
    "text": "Hey <at>Some User</at> check out this message",
    "entities": [
        {
            "type":"mention",
            "mentioned":{
                "id":"some.user@company.com",
                "name":"Some User"
            },
            "text": "<at>Some User</at>"
        }
    ]
}' <webhook_url>

As previously noted, this example works as intended. However, I'm having some trouble finding a good reference for the JSON format.

This doesn't appear to be the legacy MessageCard format or the Adaptive Card format, but potentially the format noted here:

https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/channel-and-group-conversations?tabs=json#add-mentions-to-your-messages

If this library implements the Adaptive Card format, the desired mention support would be provided, but the JSON snippet you provided appears to be much simpler. If this library implements support for that format, the desired functionality can be added sooner.

I expect that I'm overlooking it, but if you happen to have a reference to share that would be appreciated.

@ghokun
Copy link

ghokun commented Jan 28, 2022

I was looking for a way to mention user names when a pull request is opened on gitlab through gitlab-teams integration. I was not successful but saw this repository. I think this message format is for bot api but works in webhooks regardless.

There is a website for designing adaptive cards : https://adaptivecards.io/designer/
I spent some time there but could not get mentions to work with adaptive cards.

@atc0005 atc0005 added this to the v2.8.0 milestone Feb 25, 2022
atc0005 added a commit that referenced this issue Feb 25, 2022
Summary:

- deprecate the current `API` interface
- expose `TeamsClient` to take its place
- create common interfaces and helper code to abstract any specific
  Microsoft Teams message format
- create new `botapi` package (limited functionality)
- extend existing `MessageCard` type (where needed) type to support
  new behavior
- port existing `goteamsnotify.MessageCard` types/functions/methods to
  a new `messagecard` package and deprecate existing `MessageCard`
  functionality provided by the `goteamsnotify` "base" package
- update examples to reflect changes
- restore support for overriding default `http.Client`
- restore default project-specific user agent, support for
  overriding the default from client code

While making these changes I've refactored code and attempted to
clearly communicate which existing code/functionality is being
deprecated, all without introducing breaking changes for client code.

The `botapi` package added in this collection of changes is a minimal
implementation. This package is intended to provide limited user
mention functionality for channel updates as a "bridge" until future
`Adaptive Card` support can be implemented.

A future implementation of `Adaptive Card` support would provide a
more complete experience, presumably providing a superset of the
limited support in the `botapi` package and existing `MessageCard`
functionality.

refs GH-127
refs GH-134
refs GH-135
refs GH-154
@atc0005
Copy link
Owner

atc0005 commented Feb 25, 2022

@fc-ds

Initial support available here:

https://github.com/atc0005/go-teams-notify/releases/tag/v2.7.0-alpha.1

Example here:

// init the client
mstClient := goteamsnotify.NewTeamsClient()
webhookUrl := "https://outlook.office.com/webhook/YOUR_WEBHOOK_URL_OF_TEAMS_CHANNEL"
// setup message
msg := botapi.NewMessage().AddText("Hello there!")
// add user mention
if err := msg.Mention("John Doe", "jdoe@example.com", true); err != nil {
fmt.Printf(
"failed to add user mention: %v",
err,
)
}
// send message
if err := mstClient.Send(webhookUrl, msg); err != nil {
fmt.Printf(
"failed to send message: %v",
err,
)
os.Exit(1)
}

Feedback is welcome.

This is a pretty limited implementation; a more complete implementation is planned for a future release once Adaptive Card support is added. This upcoming release is intended to lay the foundation for that future support.

@atc0005
Copy link
Owner

atc0005 commented Apr 10, 2022

@fc-ds

Initial support available here:

https://github.com/atc0005/go-teams-notify/releases/tag/v2.7.0-alpha.1

Example here:

// init the client
mstClient := goteamsnotify.NewTeamsClient()
webhookUrl := "https://outlook.office.com/webhook/YOUR_WEBHOOK_URL_OF_TEAMS_CHANNEL"
// setup message
msg := botapi.NewMessage().AddText("Hello there!")
// add user mention
if err := msg.Mention("John Doe", "jdoe@example.com", true); err != nil {
fmt.Printf(
"failed to add user mention: %v",
err,
)
}
// send message
if err := mstClient.Send(webhookUrl, msg); err != nil {
fmt.Printf(
"failed to send message: %v",
err,
)
os.Exit(1)
}

Feedback is welcome.

This is a pretty limited implementation; a more complete implementation is planned for a future release once Adaptive Card support is added. This upcoming release is intended to lay the foundation for that future support.

Initial Adaptive Card support has been added as of this release:

https://github.com/atc0005/go-teams-notify/releases/tag/v2.7.0-alpha.2

Feedback is very much encouraged so issues can be found/resolved before the stable v2.7.0 release (date TBD). Discussion thread here: #163

The botapi package intended as temporary support for user mentions has been removed as the generated payloads have been found to be intermittently rejected by the Teams API (atc0005/send2teams#225).

Examples for the new package can be found here:

https://github.com/atc0005/go-teams-notify/tree/master/examples/adaptivecard

An equivalent example for what I provided previously:

func main() {
// Initialize a new Microsoft Teams client.
mstClient := goteamsnotify.NewTeamsClient()
// Set webhook url.
webhookUrl := "https://outlook.office.com/webhook/YOUR_WEBHOOK_URL_OF_TEAMS_CHANNEL"
// Setup empty message.
msg := adaptivecard.NewMessage()
// Add user mention and specified text.
if err := msg.Mention(true, "John Doe", "jdoe@example.com", "Hello there!"); err != nil {
log.Printf(
"failed to add user mention: %v",
err,
)
os.Exit(1)
}
// Send the message with default timeout/retry settings.
if err := mstClient.Send(webhookUrl, msg); err != nil {
log.Printf(
"failed to send message: %v",
err,
)
os.Exit(1)
}
}

Thanks for your interest in this project.

@atc0005 atc0005 removed the help wanted Extra attention is needed label Apr 14, 2022
@atc0005
Copy link
Owner

atc0005 commented Jun 29, 2022

No negative feedback has been received for the v2.7.0-alpha.2 release thus far.

I'm considering this resolved for the v2.7.0 release.

@atc0005 atc0005 closed this as completed Jun 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants