microsoft / appcenter

Central repository for App Center open source resources and planning.
https://appcenter.ms
Creative Commons Attribution 4.0 International
1.01k stars 225 forks source link

Webhook for Discord #1862

Closed jkapsouras closed 3 years ago

jkapsouras commented 4 years ago

I recently started using Discord app with my team for a new app. One of the first things I made (as in slack) I added a webhook to get notifications for crashes and builds. I added a webhook but when I was testing it I was getting an error (in the settings of the appcenter app). I contacted customer support and we managed to almost fix the issue by adding a webhook that was successful when tested from the settings. The problem is that it only works with the test in the settings. It does not trigger neither with crashes nor with builds. So my feature request is to add working webhooks with Discord app. Maybe with special instructions for adding (as with github and slack).

Thanks for reading my request!

edenilsonfe commented 4 years ago

hey @jkapsouras, are you still using Discord to receive notifications about Crashes and builds? I'm trying to config a webhook to send a notification to Discord but I receive this message after tap on the 'Test webhook' button: "Test failed. Verify that the URL is a valid webhook". Did you solve that? thanks!

jkapsouras commented 4 years ago

The first solution was to set the Webhook as a slack web hook. This made the test button work but the hook was not working properly (it was only triggered from the test button and not from the actual project). Shuhao from AppCenter team send me a very detailed email of how make the Webhook to work using azure functions. I didn't try it yet because I want this for a side project of mine and I am out of time this period. I'll give it a try as soon as I can. I attach below Shuhao's answer for you to try it:


I have helped you to check the Webhook issue:

Here is my conclusion for the issue, hope it could help you to understand the issue.

Why the test work but the Build, Crash and others not work? As I mentioned, App center only support Slack and Microsoft Teams currently. And the Discord support a Slack Compatible webhook, but it seems not fully compatible with App Center. App Center send webhook test message like: { "text": "test message" } But the App Center webhook such as Build, crash and others do not save message in the "text" node in JSON, and discord seems only get the message from "text" node. Here is the App center example webhook payload: https://docs.microsoft.com/en-us/appcenter/dashboard/webhooks/#example-webhook-payload

Is any method could help you using the webhook in Discord? Yes, but a bit of difficult to do that. You could do this with the Microsoft Azure Function or write codes in your own server to convert the App Center payload to the discord compatible payload.

Here is some document could help you: https://docs.microsoft.com/en-us/appcenter/dashboard/webhooks/#custom-webhook-support https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-serverless-api

I also do some research for this issue, I write node.js code in Azure Function and it works well, and I could get Build message in discord (I put the code sample in the end of the conversation, and the returned message could be write more friendly)

You could also submit a feature request for App Center for this feature. The feature request item is near the contact support.

Hope it could help you on this issue, feel free to contact us if you have any issues. Thank you and have a nice day! blush

Best Wishes, Shuhao

Sample code:

requestMeth = require('request');

module.exports = async function (context, req) {

context.log('JavaScript HTTP trigger function processed a request.');

if (req.query.name || (req.body)) {

    let json = {

        text: req.body

    };

    let data = JSON.stringify(json)

    requestMeth.post(

        'https://discord.com/api/webhooks/xxxxxxxxxx/xxxxxxxxx/slack', {

            json: {

                text: data

            }

        },

        (error, res, body) => {

            if (error) {

                context.error(error)

                return

            }

            context.log(statusCode: ${res.statusCode})

            context.log(body)

        }

    )

    context.res = {

        status: 200,

    }

} else {

    context.res = {

        status: 400,

        body: "Please pass a name on the query string or in the request body"

    };

}

}

edenilsonfe commented 4 years ago

I'll try to use this solution for now. I'll test it as soon as I can. Thank you @jkapsouras!

jkapsouras commented 4 years ago

I'll try to use this solution for now. I'll test it as soon as I can. Thank you @jkapsouras!

Let me know if you make it work!

ghost commented 3 years ago

This issue has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs within 15 days of this comment.

ghost commented 3 years ago

This issue will now be closed because it hasn't had any activity for 15 days after stale. Please feel free to open a new issue if you still have a question/issue or suggestion.

gg-ballin commented 1 year ago

@edenilsonfe did the solution worked?