ONEARMY / community-platform

A platform to build useful communities that aim to tackle global problems
https://platform.onearmy.earth
MIT License
1.14k stars 386 forks source link

[feature request] Enable Discord webhooks for Project Kamp #3693

Closed pizzaisdavid closed 2 months ago

pizzaisdavid commented 3 months ago

Setup Discord webhooks for Project Kamp. Currently they have the Research module enabled, and it would be good if there is an automated message in the activity-bot channel.

Mentioned by Dave here --> https://github.com/ONEARMY/community-platform/pull/3684#issuecomment-2188245594

~This ticket is kinda pointless to implement until https://github.com/ONEARMY/community-platform/pull/3684 is merged.~

pizzaisdavid commented 3 months ago

Please someone with Label privileges, make a Label called like "Maintainer only" or "requires Maintainer credentials" and then apply that label to this issue.

pizzaisdavid commented 3 months ago

In the future, it might make sense to send the notifications for each project to different channels, because maybe not everyone is interested in every project.. but for now it is enough to jam it into the already existing channel (lol.)

pizzaisdavid commented 3 months ago

Found some docs:

https://github.com/ONEARMY/community-platform/blob/8e2432e8ed5729674a661c144f86c597de576ca9/packages/documentation/docs/Deployment/circle-ci.md?plain=1#L88

pizzaisdavid commented 3 months ago

https://firebase.google.com/docs/functions/config-env?gen=1st#set_environment_configuration_with_the

pizzaisdavid commented 3 months ago

Someone with access to production via command line, do:

firebase use production
firebase functions:config:get

Then save that on your computer and let me know.

benfurber commented 3 months ago

@pizzaisdavid Messaged you on discord.

pizzaisdavid commented 3 months ago

Thanks Ben

Please read step 3, as there are possible "business" decisions that might need to be discussed or you can do whatever you want.

1) We want to modify the Project Kamp config, so first we select that:

firebase use project-kamp-production

2) before modifying, we should check what is currently there:

firebase functions:config:get

I recommend saving it into a text file as a backup.

3) Make the change:

firebase functions:config:set integrations.discord_alert_channel_webhook="VALUE"

I assume that there is no value for discord_alert_channel_webhook, also, given how functions:config:set works, if the integrations object does not exist, it will create it.

"VALUE" should be changed to something else. There are options, which are driven by business decisions:

4) Do a "get" again, to check that things look correct.

5) Deploy (?)

6) Make an Update on a Research Article on Production to test (?)

@benfurber

pizzaisdavid commented 3 months ago

@davehakkens any special opinion about the name and avatar of the Discord bot that posts for Project Kamp (See step 3 of my previous comment for some details.)

davehakkens commented 3 months ago

Similair pattern as the others. Name: Community Platform Image: logo

Should I make a webhook in Discord like the others?

afbeelding afbeelding

Edit: made one and send you the url on Discord DM

pizzaisdavid commented 3 months ago

Ben mentioned to me he made the changes and deployed.

So if anyone wants to test this, if they have admin or editor role on Project Kamp, just make a new research article, and then create an update for it.

Otherwise, we just wait.

davehakkens commented 3 months ago

Made an update here. Lets see https://community.projectkamp.com/research/should-we-get-a-tractor-to-work-on-the-land

pizzaisdavid commented 3 months ago

I searched the activity-bot channel, and didn't see it. I am 99.9% certain I didn't miss it.

So something isn't working correctly.

It is working correctly for precious plastic (https://discord.com/channels/586676777334865928/599259846767935519/1257436141624365208) so I would guess the code itself is fine, but something is wrong with the configuration/discord bot.

Maybe over the next days me and someone with access to firebase can have a call, as that might be quicker.

Or I suggest going to: https://console.firebase.google.com/u/0/project/project-kamp-production/functions (or https://console.firebase.google.com/u/0/project/project-kamp-community/functions) not sure which one is correct based on https://github.com/ONEARMY/community-platform/blob/master/.firebaserc

Then looking for the row with integrations-notifyResearchUpdatePublished, clicking the three dots, clicking view logs, and seeing what we see there. Ideally finding the edit that Dave made and seeing what actually happened.

Or could also doublecheck the functions config thing.

davehakkens commented 2 months ago

Hi @pizzaisdavid sorry for the slow reply. Slipped of the todo list. I gave you acces to the PK database. You need anything else to finish it up?

pizzaisdavid commented 2 months ago

Thanks, Dave. I got the email.

TL;DR: I think I fixed it, it should work after the next deploy, in theory.

Details:

Checked the functions environment variable, it looks okay. But the logs say no webhook URL configured.

https://console.cloud.google.com/logs/query;query=%2528resource.type%3D%22cloud_function%22%20resource.labels.function_name%3D%2528%22integrations-notifyResearchUpdatePublished%22%2529%20resource.labels.region%3D%22us-central1%22%2529%20OR%20%2528resource.type%3D%22cloud_run_revision%22%20resource.labels.service_name%3D%2528%22integrations-notifyResearchUpdatePublished%22%2529%20resource.labels.location%3D%22us-central1%22%2529;cursorTimestamp=2024-07-21T17:28:20.371803Z;duration=PT1H?authuser=0&project=project-kamp-community&hl=en

In the code, it is like this: CONFIG.integrations.discord_webhook

But in the config it is like this:

{
  "integrations": {
    "discord_alert_channel_webhook": "whatever",
  },
}

So we actually configured the wrong thing. discord_alert_channel_webhook is for error reporting. I have removed that from the config, as the discord link there was to the public bot activity channel, and I don't want errors with possibly private information going there.

The config now looks like:

{
  "integrations": {
    "discord_webhook": "whatever",
  },
}

Which should be correct.

pizzaisdavid commented 2 months ago

Er, also in full disclosure, I gave myself admin privileges for project kamp by editing my user entry. :sunglasses:

benfurber commented 2 months ago

Doing a deploy shortly.

pizzaisdavid commented 2 months ago

objective completed: image

davehakkens commented 2 months ago

Niceee. Thanks @pizzaisdavid for taking on this item!