isso icon indicating copy to clipboard operation
isso copied to clipboard

Feature: add webhook notification capability

Open Guts opened this issue 3 years ago • 16 comments

I propose here to add the possibility to send a notification to a web hook for each new comment.

Notable changes

  • creation of a new WebHook class in the notifications module
  • by default, it sends a POST request with the same metadata as the mail notification (name, mail and site of the author as well as the moderation links)
  • add requests as dependency
  • possibility for the end user to pass a JSON template to the webhook (useful for tools allowing formatting, like Slack/Teams/Matrix...). An example of template for Slack is provided (into contrib subfolder) with this render:

image

Questions

  • Maybe it is possible with Werkzeug, Flask or the stdlib directly for the POST request? I'm not expert on this side so, don't hesitate on review my code.
  • I wanted to use f-strings but apparently the project is still tested on Python 3.5 (which has reached EOL), but not 3.9. Is it a voluntary choice?
  • I had to fix dependencies consistency between setup.py and tox.ini, in order to get CI fixed. Requirements are not well documented and the development workflow is quite unclear. Would you accept a PR to switch to requirements.txt files and/or pyproject.tom (recomended by tox anyway)?

Misc

  • add cache to Travis to make it faster
  • Close my question #722

Guts avatar May 01 '21 10:05 Guts

ping @posativ @ix5 @blatinier : any chance to see it merged or reviewed?

Guts avatar Jun 17 '21 05:06 Guts

Can't say much, but here are my thoughts:

ix5 avatar Jun 17 '21 14:06 ix5

Thanks for your feedback.

f-strings are pretty dangerous, see Armin Ronacher: Be Careful with Python's New-Style String Format

I did not know that but it's quite old (not sure it's still applicable) and it's a concern only when we format some secret no? If you prefer, we can switch to f"{var}" or "%s" % var.

Avoid adding new dependencies. POST requests can be done with urllib

Sure but it would be quite harder to handle different cases (HTTP warnings, redirections, etc...).

Squash your commits

I will.

Guts avatar Jun 17 '21 16:06 Guts

It would be great if this had some unit tests.

jelmer avatar Jun 21 '21 23:06 jelmer

Sure!

I did not write them because I can't find which tests framework is recommended.

Can you tell me which one please? (pypi package name)

Guts avatar Jun 22 '21 07:06 Guts

We're using nosetests; you can invoke them with nose or by running "make test"

jelmer avatar Jun 22 '21 09:06 jelmer

We're using nosetests; you can invoke them with nose or by running "make test"

Ok. What I need is the PyPi package to install it as testing dependency in a virtual env (I don't want to install something widely on my system). I can't find noestests on pypi.org but I've found 2 nose* packages: this one https://pypi.org/project/nose/ or this one https://pypi.org/project/nose2/?

Guts avatar Jun 22 '21 10:06 Guts

I think the pypi name is just "nose", but you should also be able to just use python's standard unittest framework to run the tests - we don't use anything nose-specific.

jelmer avatar Jun 22 '21 18:06 jelmer

I think the pypi name is just "nose", but you should also be able to just use python's standard unittest framework to run the tests - we don't use anything nose-specific.

Good news because running make test returns an error (Ubuntu 20.04, after make init with node 14):

:~/Git/External/isso$ make test
python3 setup.py nosetests
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: invalid command 'nosetests'
make: *** [Makefile:71 : test] Erreur 1

Thanks for your help. I'll try to write some unit tests with the standard lib.

Guts avatar Jun 22 '21 19:06 Guts

nose is only a runner. You can also run them with python3 -m unittest discover isso/tests or by using pytest which also includes a runner.

vincentbernat avatar Jun 22 '21 21:06 vincentbernat

I & @mskian ended up creating this - https://github.com/mskian/isso-telegram-notifier

mcnaveen avatar Oct 09 '21 13:10 mcnaveen

I & @mskian ended up creating this - https://github.com/mskian/isso-telegram-notifier

Nice work! Why not develop it right into Isso?

Guts avatar Oct 09 '21 14:10 Guts

I & @mskian ended up creating this - https://github.com/mskian/isso-telegram-notifier

Nice work! Why not develop it right into Isso?

If this was added to mainline isso, it would be hard to make sure that it kept working - the maintainers can't test with lots of different configurations.

jelmer avatar Oct 09 '21 20:10 jelmer

Nice work! I have not verified the functionality myself, but the code looks neat.

Please add (unit) tests as requested by @jelmer

ix5 avatar Dec 21 '21 22:12 ix5

@Guts this is a great feature, would you mind rebasing and addressing the points raised by jelmer and myself?

ix5 avatar Feb 10 '22 20:02 ix5

It'll be great to have this feature. It'll enable me to trigger a build of my static website in which I render the Isso comments at build time.

abhin4v avatar Feb 25 '23 14:02 abhin4v