mborsetti / webchanges

webchanges anonymously checks web content (including images) and commands for changes, delivering instant notifications and AI-powered summaries to your favorite platform.
https://pypi.org/project/webchanges/
Other
37 stars 6 forks source link

RuntimeError: Webhook server error: {"message": "Cannot send an empty message", "code": 50006 #33

Closed ghost closed 2 years ago

ghost commented 2 years ago

Trying to understand why the same job that sends text to pushover is not sending text via the webhook feature and Discord

Did a bit of googling and looking through the docs but must be missing some bit of info. Hoping you have some insight.

My Discord link has been edited.


{"status":1,"request":"e3b47349-c696-4e3c-a05b-ffe89565ce8e"}
2022-04-12 02:42:43,222 reporters[4497558976] INFO: Submitting with webhook (<class 'webchanges.reporters.WebhookReporter'>)
2022-04-12 02:42:43,226 reporters[4497558976] DEBUG: Sending request to webhook with text:1. NEW: 32_NASA LC Records

**job result text here**

2022-04-12 02:42:43,228 connectionpool[4497558976] DEBUG: Starting new HTTPS connection (1): discord.com:443
2022-04-12 02:42:43,389 connectionpool[4497558976] DEBUG: https://discord.com:443 "POST /api/webhooks/xxx/xxxxx HTTP/1.1" 400 58
Traceback (most recent call last):
  File "/Users/john/.pyenv/versions/3.10.3/bin/webchanges", line 8, in <module>
    sys.exit(main())
  File "/Users/john/.pyenv/versions/3.10.3/lib/python3.10/site-packages/webchanges/cli.py", line 232, in main
    urlwatch_command.run()
  File "/Users/john/.pyenv/versions/3.10.3/lib/python3.10/site-packages/webchanges/command.py", line 682, in run
    self.urlwatcher.close()
  File "/Users/john/.pyenv/versions/3.10.3/lib/python3.10/site-packages/webchanges/main.py", line 115, in close
    self.report.finish(jobs_file=self.jobs_storage.filename)
  File "/Users/john/.pyenv/versions/3.10.3/lib/python3.10/site-packages/webchanges/handler.py", line 482, in finish
    ReporterBase.submit_all(self, self.job_states, duration, jobs_file)
  File "/Users/john/.pyenv/versions/3.10.3/lib/python3.10/site-packages/webchanges/reporters.py", line 214, in submit_all
    subclass(report, cfg, job_states, duration, jobs_file).submit()
  File "/Users/john/.pyenv/versions/3.10.3/lib/python3.10/site-packages/webchanges/reporters.py", line 1364, in submit
    res = self.submit_to_webhook(webhook_url, chunk)
  File "/Users/john/.pyenv/versions/3.10.3/lib/python3.10/site-packages/webchanges/reporters.py", line 1379, in submit_to_webhook
    raise RuntimeError(f'Webhook server error: {result.text}')
RuntimeError: Webhook server error: {"message": "Cannot send an empty message", "code": 50006}
mborsetti commented 2 years ago

OK, found the issue: the webhook has a different payload structure for Discord, so it wasn't working. Ended up implementing a separate reporter for Discord with additional functionality. It should work now; it's available as a release candidate in the unreleased branch.

Would you be so kind to test it? If so, you can install it with

pip install git+https://github.com/mborsetti/webchanges.git@unreleased

The documentation for the new Discord reporter is at https://webchanges.readthedocs.io/en/unreleased/reporters.html#discord (oops, I just noticed that the alphabetical order needs to be restored; will fix).

Thanks!

ghost commented 2 years ago

Thank you for making those changes! There are a few limitations with Pushover - mainly message length being clipped when more than one job is reported.

The instructions need some editing. I took a stab at changing from "webhooks" to "discord" for the reporter name after "webhooks" failed... and it's working.

I believe the reporter also requires a max_message_length: 2000 ?

As far as the config.yaml is concerned, do we need to keep all of the reporters listed even though they are not enabled? At some point when in debug mode I noticed that webchanges considered it malformed and reverted to a default config.yaml if some of the reporters were missing.

2022-04-12 16:51:45,717 storage[4470128064] INFO: The configuration file /Users/john/Library/Preferences/webchanges/config.yaml is missing directive(s); the following default values are being used:
report:
  email:
    enabled: false
    from: ''
    html: true
    method: smtp
    sendmail:
      path: sendmail
    smtp:
      auth: true
      host: localhost
      insecure_password: ''
      port: 25
      starttls: true
      user: ''
    subject: '[webchanges] {count} changes: {jobs}'
    to: ''
  ifttt:
    enabled: false
    event: ''
    key: ''
  mailgun:
    api_key: ''
    domain: ''
    enabled: false
    from_mail: ''
    from_name: ''
    region: us
    subject: '[webchanges] {count} changes: {jobs}'
    to: ''
  matrix:
    access_token: ''
    enabled: false
    homeserver: ''
    room_id: ''
  prowl:
    api_key: ''
    application: ''
    enabled: false
    priority: 0
    subject: '[webchanges] {count} changes: {jobs}'
  pushbullet:
    api_key: ''
    enabled: false
  telegram:
    bot_token: ''
    chat_id: ''
    enabled: false
    silent: false
  webhook:
    enabled: false
    markdown: false
    max_message_length: null
    webhook_url: ''
  xmpp:
    enabled: false
    insecure_password: ''
    recipient: ''
    sender: ''
See documentation at https://webchanges.readthedocs.io//en/stable/configuration.html
ghost commented 2 years ago

Anyway to get links and text to show up in Discord as clickable web links? I am guessing no since it's embedded information. I am also not getting colored text in Discord.

mborsetti commented 2 years ago

Thanks. The documentation was indeed rushed for this release candidate and will get cleaned up (thanks for the additional inputs) before final release.

Correct; you can remove the reporters not in use from config.yaml; the alert listing missing keys is there in verbose mode to make it easier to understand what's going on for debugging purposes.

I personally am not a Discord user and don't know if/how clickable web links can be made; if you find out how, please share. Similarly the colorization was an upstream contribution and am surprised to read that it isn't working :(

ghost commented 2 years ago

Just adding more info for those interested. The links and color are there when viewed in a browser - just not on the iOS Discord.app... yet.

Markdown is not fully supported from computer to mobile. I'm sorry for any hassle.

I know that we want to reach full parity between PC and Mobile and we have a lot of devs who use the platform so I hope sooner rather than later, but unfortunately I don't have any ETA on it.