Code Monkey home page Code Monkey logo

Comments (42)

iamtraction avatar iamtraction commented on August 20, 2024

It works over HTTPS, the WebCmdletWebResponseException error means something's wrong with the webhook data or it's malformed.

Can you add this line just before Invoke-RestMethod and test it again.

Write-Output "$WEBHOOK_DATA"

This will log the webhook data in the AppVeyor logs. And then can you send the logged webhook data or link to the build so I can see what's the issue?

from appveyor-discord-webhook.

Apjue avatar Apjue commented on August 20, 2024

Here are the logs

[Webhook]: Sending webhook to Discord...
{
  "username": "",
  "avatar_url": "https://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Appveyor_logo.svg/256px-Appveyor_logo.svg.png",
  "embeds": [ {
    "color": 3066993,
    "author": {
      "name": "Job #1 (Build #327) Passed - S6066/Teal",
      "url": "https://ci.appveyor.com/project/S6066/teal/build/luacomponents v0.x (#327)",
      "icon_url": "https://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Appveyor_logo.svg/256px-Appveyor_logo.svg.png"
    },
    "title": "Don't push this commit",
    "url": "",
    "description": " S6066 authored & committed",
    "fields": [
      {
        "name": "Commit",
        "value": "[`fd08b9f`](https://github.com/S6066/Teal/commit/fd08b9fd25af2f0bcb2763a5406d990b7105f6a9)",
        "inline": true
      },
      {
        "name": "Branch/Tag",
        "value": "[`luacomponents`](https://github.com/S6066/Teal/tree/luacomponents)",
        "inline": true
      }
    ],
    "timestamp": "2018-06-06T11:37:33Z"
  } ]
}
Invoke-RestMethod : {"embeds": ["0"]}

The url field is empty, I have correctly set it in Appveyor settings page though? https://i.imgur.com/IrEpBYQ.png
Edit: Nevermind, that's probably not the problem

from appveyor-discord-webhook.

iamtraction avatar iamtraction commented on August 20, 2024

Your webhook data looks fine to me.

Is this line from your logs too?

Invoke-RestMethod : {"embeds": ["0"]}

This is the line that concerns me.

from appveyor-discord-webhook.

Apjue avatar Apjue commented on August 20, 2024

Yup, that line is from my logs, just before the error

from appveyor-discord-webhook.

iamtraction avatar iamtraction commented on August 20, 2024

Can I get a link to this AppVeyor build? I need to see why that line is being logged. Most probably that's the line that's causing the issue.

from appveyor-discord-webhook.

Apjue avatar Apjue commented on August 20, 2024

Sure - https://ci.appveyor.com/project/S6066/teal/build/job/gh9nodyavde6gqy8

from appveyor-discord-webhook.

iamtraction avatar iamtraction commented on August 20, 2024

I don't see any issue that could be causing this. Can you try this for any other repository? Maybe some configuration or environment in this repository itself isn't working with the webhook.

Here's a link to a working configuration of AppVeyor, if it helps: https://github.com/TheBastionBot/Bastion/blob/master/appveyor.yml
And a screenshot of the received webhook:
image

from appveyor-discord-webhook.

Apjue avatar Apjue commented on August 20, 2024

With this code on a new repo, I still have the same error https://github.com/S6066/test-things/blob/3da2dd685d3fc85daf8fec6d94059ef700fdb9bf/appveyor.yml
But with this code https://github.com/S6066/test-things/blob/8337baed7ef1a665a1f0b95db8f93cd1fec5bb23/appveyor.yml (notice the % instead of $env), I have this output

[Webhook]: Sending webhook to Discord...
Invoke-RestMethod : Invalid URI: The hostname could not be parsed.
At C:\projects\test-things\.appveyor_discord_webhook.ps1:89 char:1
+ Invoke-RestMethod -Uri "$WH__WEBHOOK_URL" -Method "POST" -UserAgent " ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Invoke-RestMethod], UriFormatException
    + FullyQualifiedErrorId : System.UriFormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
 
[Webhook]: Successfully sent the webhook.

Is the WEBHOOK_URL variable really supposed to be encrypted?

from appveyor-discord-webhook.

iamtraction avatar iamtraction commented on August 20, 2024

Secure variables are not decoded during Pull Request
Source: https://www.appveyor.com/docs/build-configuration/#secure-variables

That is the reason it's got decoding the Webhook URL. from the secure environment variable and that's why you're getting Invalid URL error..

Instead of adding the WEBHOOK_URL env. var. in your appveyor.yml configuration file, add it in the project settings in AppVeyor and see if this works.

from appveyor-discord-webhook.

Apjue avatar Apjue commented on August 20, 2024

I already tried putting it in the project settings, in the .yml, and in both. Nothing worked

from appveyor-discord-webhook.

iamtraction avatar iamtraction commented on August 20, 2024

See the readme file and follow the guide there. And Use the script from this repo not from your fork. And see if that works.

from appveyor-discord-webhook.

Apjue avatar Apjue commented on August 20, 2024

I was following the guide, and the altered script works
If I paste the 2 exact lines from the Readme, I have the same result. (variable's encryption doesn't change anything)

[Webhook]: Sending webhook to Discord...
Invoke-RestMethod : {"embeds": ["0"]}
At C:\projects\test-things\send.ps1:87 char:1
+ Invoke-RestMethod -Uri "$WEBHOOK_URL" -Method "POST" -UserAgent "AppV ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
[Webhook]: Successfully sent the webhook.

from appveyor-discord-webhook.

iamtraction avatar iamtraction commented on August 20, 2024

Can you add these to your AppVeyor configuration and try?

image:
  - Visual Studio 2017
platform: x64

I don't see anything else other than the difference in environment (especially if the PowerShell versions differ) that might be causing that issue.

from appveyor-discord-webhook.

Apjue avatar Apjue commented on August 20, 2024

Same thing happen.
There's clearly a problem in the script. I putted the webhook url hardcoded, and without encryption in appveyor.yml, and the error still occurs

from appveyor-discord-webhook.

iamtraction avatar iamtraction commented on August 20, 2024

Can you test the script in your local computer and see if it's working for you there?

from appveyor-discord-webhook.

Apjue avatar Apjue commented on August 20, 2024

I removed everything related to git/appveyor and ran it, unsurprinsingly it still doesn't work

[Webhook]: Sending webhook to Discord...
Invoke-RestMethod : {"embeds": ["0"]}
Au caractère D:\Users\Samy\Downloads\send.ps1:65 : 1
+ Invoke-RestMethod -Uri "$WEBHOOK_URL" -Method "POST" -UserAgent "AppV ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation : (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebE
   xception
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
[Webhook]: Successfully sent the webhook.

from appveyor-discord-webhook.

Apjue avatar Apjue commented on August 20, 2024

Wait, I had the errors in the log but there was a message in the discord channel

from appveyor-discord-webhook.

iamtraction avatar iamtraction commented on August 20, 2024

Add the -Verbose option at the end of Invoke-WebRequest command as shown below and see if it gives more verbose error:

Invoke-RestMethod -Uri "$WEBHOOK_URL" -Method "POST" -UserAgent "AppVeyor-Webhook" `
  -ContentType "application/json" -Header @{"X-Author"="k3rn31p4nic#8383"} `
  -Body $WEBHOOK_DATA -Verbose

from appveyor-discord-webhook.

Apjue avatar Apjue commented on August 20, 2024
[Webhook]: Sending webhook to Discord...
COMMENTAIRES : POST
(webhook url) with -1-byte payload
Invoke-RestMethod : {"embeds": ["0"]}
Au caractère D:\Users\Samy\Downloads\send.ps1:65 : 1
+ Invoke-RestMethod -Uri "$WEBHOOK_URL" -Method "POST" -UserAgent "AppV ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation : (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebE
   xception
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
[Webhook]: Successfully sent the webhook.

from appveyor-discord-webhook.

iamtraction avatar iamtraction commented on August 20, 2024

I've made the webhook data a little simpler just to test if there's something wrong with the data. Try this webhook script instead of the old one: https://ghostbin.com/paste/t6xsk

from appveyor-discord-webhook.

Apjue avatar Apjue commented on August 20, 2024

It works, I just received a message, with no error in the logs:

COMMENTAIRES : POST
(webhook url) with -1-byte payload
COMMENTAIRES : received 0-byte response of content type text/html; charset=utf-8

from appveyor-discord-webhook.

iamtraction avatar iamtraction commented on August 20, 2024

Which proves there's something wrong in the webhook data. Try this now: https://ghostbin.com/paste/t6xsk

from appveyor-discord-webhook.

Apjue avatar Apjue commented on August 20, 2024

Before you sent me the code, I tried some things

$WEBHOOK_DATA="{
  ""username"": ""AppVeyor"",
  ""avatar_url"": ""$AVATAR"",
  ""embeds"": [ {
    ""color"": $EMBED_COLOR,
    ""author"": {
      ""name"": ""AppVeyor"",
      ""icon_url"": ""$AVATAR""
    },
    ""title"": ""lorem"",
    ""description"": ""ipsum"",
    ""fields"": [
      {
        ""name"": ""field 1 name"",
        ""value"": ""field 1 value"",
        ""inline"": true
      }
    ]
  } ]
}"

This works. But when adding to the fields field a second... field with the value field empty (""value"": """",), it doesn't work
The script you sent me works

from appveyor-discord-webhook.

iamtraction avatar iamtraction commented on August 20, 2024

Empty value fields will not work, Discord doesn't allow that.
Try with this one now, I'm trying to eliminate the problem one by one: https://ghostbin.com/paste/zcrr3

from appveyor-discord-webhook.

Apjue avatar Apjue commented on August 20, 2024

It works

from appveyor-discord-webhook.

iamtraction avatar iamtraction commented on August 20, 2024

Okay, the only thing that was removed there was the timestamp.
Try with the original one now: https://raw.githubusercontent.com/k3rn31p4nic/appveyor-discord-webhook/master/send.ps1

from appveyor-discord-webhook.

Apjue avatar Apjue commented on August 20, 2024

Perfect, the original works locally

from appveyor-discord-webhook.

iamtraction avatar iamtraction commented on August 20, 2024

Now try that in AppVeyor.

from appveyor-discord-webhook.

Apjue avatar Apjue commented on August 20, 2024

Nope, doesn't work. Even when specifying directly the webhook url, quoted or not

from appveyor-discord-webhook.

iamtraction avatar iamtraction commented on August 20, 2024

Try with all the scripts that I sent in the past few minutes. And let me know which one works and which doesn't, if you can.

from appveyor-discord-webhook.

Apjue avatar Apjue commented on August 20, 2024

https://ghostbin.com/paste/t6xsk works
https://ghostbin.com/paste/zcrr3 doesn't work

from appveyor-discord-webhook.

iamtraction avatar iamtraction commented on August 20, 2024

Try this one again: https://ghostbin.com/paste/t6xsk

from appveyor-discord-webhook.

Apjue avatar Apjue commented on August 20, 2024

It's the same link, but it works

from appveyor-discord-webhook.

iamtraction avatar iamtraction commented on August 20, 2024

Link's the same, but I edited the content. Okay, so I've isolated the issue to all the URLs in the script. So something's wrong with at least one of the URL which is preventing it from running. Can you try removing the URLs in the embed object one by one, from the original script, and see which URL's causing trouble?

from appveyor-discord-webhook.

Apjue avatar Apjue commented on August 20, 2024

So now I'm stuck with "cannot send an empty message" with https://github.com/S6066/test-things/blob/master/send.ps1

from appveyor-discord-webhook.

iamtraction avatar iamtraction commented on August 20, 2024

That means that you're sending an empty embed object to Discord. And Discord is blocking that.
Did you try and remove the URLs from the default script and did it work?

from appveyor-discord-webhook.

Apjue avatar Apjue commented on August 20, 2024

I was trying, and it didn't work because of that error

from appveyor-discord-webhook.

iamtraction avatar iamtraction commented on August 20, 2024

Try logging the WEBHOOK_DATA variable and show me the output (the value of WEBHOOK_DATA).

from appveyor-discord-webhook.

Apjue avatar Apjue commented on August 20, 2024

Stupid me. I placed a # in the string to comment the url but forgot it was... in a string. GH coloration didn't help me
It works when deleting the url field in embeds::author

from appveyor-discord-webhook.

iamtraction avatar iamtraction commented on August 20, 2024

Can you log the author URL and show me the output? So I can know why the author URL is having issues?

from appveyor-discord-webhook.

Apjue avatar Apjue commented on August 20, 2024

Write-Output $env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/build/$env:APPVEYOR_BUILD_VERSION
gives
S6066/test-things/build/master v0.x (#43)
Characters are not escaped.

from appveyor-discord-webhook.

iamtraction avatar iamtraction commented on August 20, 2024

Okay, now I know the issue. I've made a new bug report so I can work on it later: #3

I'm now closing this issue. Thank you!

from appveyor-discord-webhook.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.