tcplugins / tcWebHooks

WebHooks plugin for Teamcity. Supports many build states and payload formats.
https://netwolfuk.wordpress.com/category/teamcity/tcplugins/tcwebhooks/
155 stars 30 forks source link

Change sender in slack #190

Closed VasilevMaxim closed 2 years ago

VasilevMaxim commented 2 years ago

Hi! Sorry to write about the problem here. There is the following problem:

There is a teamcity server, the tcwebhooks plugin is installed on it.

When I insert the URL of a web hook from the Incoming Web Hooks section to the server, messages begin to be sent on my behalf, and not on behalf of the bot (TeamCity applications, that is, slack applications).

Can you tell me what I can do to make messages come from the front side of the application, and not from mine? Thanks! https://wampi.ru/image/RErsi4Z

netwolfuk commented 2 years ago

Hi @VasilevMaxim Looking at the screenshot you posted, the event is posted by the TeamCity app.

I'll have a look on the weekend and try to reproduce the problem you decride.

VasilevMaxim commented 2 years ago

@netwolfuk

I'll describe everything in more detail just in case.

If I change the URL Ebook and select the "TeamCity App" (https://wampi.ru/image/RErXgAa) init application, then the messages really come from the bot application (https://wampi.ru/image/RErX668).

However, I want the boot application to send a message not to me, but to another person (for example, "Артём Богунов").

And if I specify the Webhook URL of a team member "Артём Богунов", then messages are sent on my behalf, not on behalf of the bot (https://wampi.ru/image/RENBwnE )

Only when a team member himself visits this site and gets a Webhook URL for himself, everything starts working as it should. But you can't force every team member to do that.

But how do I do it? How do I identify the person to whom the message should come? Thanks! https://wampi.ru/image/RErXG4I

Thanks!

netwolfuk commented 2 years ago

Hi @VasilevMaxim I think this is not possible in slack when using a webhook integration. I imagine this is intentional, otherwise any webhook could impersonate any other slack user.

Is there a problem with slack messages coming from the TeamCity App user? I personally think this makes good sense.

It is possible to mention a user by mapping their git username to their slack username. When using this mapping, we can find the usernames of the change commiters and include their name in the message. I have an example somewhere on how to do that.

netwolfuk commented 2 years ago

Hi @VasilevMaxim I found the example template that uses a jsonMap to define the mappings from git username to slack username.

You can see my post here; https://github.com/tcplugins/tcWebHooks/issues/156#issuecomment-623653846 I'll do some testing and make sure it works correctly.

VasilevMaxim commented 2 years ago

Hi @netwolfuk I may have misunderstood you, but my task is as follows: I need the bot (TeamCity app) to send a message to a team member on its own, just like the Slack notification built into TeamCity does.

So that the message does not come in a dialogue with me, but in a dialogue with the bot. Thanks!

netwolfuk commented 2 years ago

Thanks @VasilevMaxim for the clarification.

The webhook uses the slack webhook API. I suspect that it would need to use the slack bot API to support your use case.

It might be possible to do a mapping of some kind, but now I understand why you'd need to create an webhook for every user on slack.

I have some experience with the slack bot API from when I wrote the tcChatBot plugin. It is much more powerful than the slack webhook API.

I'll keep thinking about it and see if I can come up with a solution.

netwolfuk commented 2 years ago

Hi @VasilevMaxim I have not been able to determine how to change the user that the webhook is posted as in slack. Sorry. I will close this topic as it's not something that I can control in tcWebHooks.