• Resolved melme

    (@melme)


    Hey there!
    I want to get a c7f to Discord. I insert the Discord-Webhook-link into settings of the c7f. But if I try, I do not get a message in Discord. Any idea, why?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Mário Valney

    (@mariovalney)

    Hi. How are you?

    Probally Discord has its own structure to accept messages from webhook.

    You should use our filters to change the data the plugin send to webhook to provide a valid Discord data.

    You can check a example in this topic.

    Thread Starter melme

    (@melme)

    Hi Mário!

    I am fine, thank you! How are you?

    I am really no coding guy. Could you help me to get the filter working? Best thing as plugin because I saw the problem with updating?

    I found the structure of discord in this link: https://birdie0.github.io/discord-webhooks-guide/discord_webhook.html

    Thread Starter melme

    (@melme)

    I used https://discohook.org/ to create a JSON for Discord. This should be the code at the end send to discord as webhook.

    {
      "content": "New message from [NAME] on your website.",
      "embeds": [
        {
          "title": "Contactform",
          "description": "**Discord-Tag:** [DISCORDTAG]\n**E-Mail:** [EMAIL]\n\n**Message**\n[MESSAGE]",
          "color": 9291330,
          "author": {
            "name": "[NAME]",
            "icon_url": "https://ennorath.org/wp-content/uploads/2020/03/mail.png"
          }
        }
      ]
    }

    My formular just has 4 fields: [NAME], [EMAIL], [DISCORDTAG] and [MESSAGES].
    [DISCORDTAG] could be empty. The other fields have to be filled.

    • This reply was modified 5 years ago by melme.
    • This reply was modified 5 years ago by melme.
    Plugin Author Mário Valney

    (@mariovalney)

    You can try use something like this filter:

    <?php
    
    add_filter( 'ctz_post_request_args', $args );
    
    function discord_ctz_post_request_args( $args ) {
        $body = json_decode( $args['body'] );
    
        // Add your own validation to change only this form
        if ( empty( $body ) ) {
            return $args;        
        }
    
        $discord_body = array(
            'content' => 'New message from ' . $body['name'] . 'on your website.',
            'embeds'  => array(
                "title": "Contactform",
                "description": sprintf( "**Discord-Tag:** %s\n**E-Mail:** %s\n\n**Message**\n%s", $body['discordtag'], $body['email'], $body['message'] ),
                "color": 9291330,
                "author": array(
                    "name": $body['name'],
                    "icon_url": "https://ennorath.org/wp-content/uploads/2020/03/mail.png",
                ),
            ),
        );
    
        $args['body'] = json_encode( $discord_body );
    
        return $args;
    }

    I was not able to test or validate any input, so add this, please.

    You should change “name”, “discordtag” and other $body['field-ids'] to match your own fields.

    I hope this can help you.

    Could you please build in an discord mode into the plugin? I don’t know howto deal with the code you pasted above.

    If not i’m going to need a full step-by-step tutorial howto get this to work.

    Thank you. ??

    Plugin Author Mário Valney

    (@mariovalney)

    Hey. How are you.

    First of all, sorry: the snippet above is broken.

    @melme please, do not use it.

    @nucce1 I created a simple plugin to allow what you want:

    https://gist.github.com/mariovalney/3f6f4ea6f864239c9f7b327e75b201e9

    You just have to download and put in plugin’s folder (or zip inside a folder and install from dashboard).

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Webhook to Discord’ is closed to new replies.