Skip to content

Commit 41def5f

Browse files
committed
[ADD] webhook_incoming: trigger actions upon incoming webhook requests
1 parent 848c21f commit 41def5f

15 files changed

Lines changed: 914 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../webhook_incoming

setup/webhook_incoming/setup.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
setup_requires=['setuptools-odoo'],
5+
odoo_addon=True,
6+
)

test-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
odoo-addon-webhook_outgoing @ git+https://github.com/OCA/webhook@refs/pull/13/head#subdirectory=setup/webhook_outgoing

webhook_incoming/README.rst

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
================
2+
Incoming Webhook
3+
================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:801eb9069d1b38681a4da1eec8219ce59055f9cea46af867d49a7be05b955dc4
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
18+
:alt: License: LGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fwebhook-lightgray.png?logo=github
20+
:target: https://github.com/OCA/webhook/tree/16.0/webhook_incoming
21+
:alt: OCA/webhook
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/webhook-16-0/webhook-16-0-webhook_incoming
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/webhook&target_branch=16.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module allow creating an automation that send webhook/requests to another systems via HTTP.
32+
33+
To create a new automation to send webhook requests, go to Settings > Automated Actions:
34+
35+
* When add an automation, choose `Custom Webhook` as action to perform.
36+
* Config Endpoint, Headers and Body Template accordingly.
37+
38+
This webhook action use Jinja and rendering engine, you can draft body template using Jinja syntax.
39+
40+
**Table of contents**
41+
42+
.. contents::
43+
:local:
44+
45+
Bug Tracker
46+
===========
47+
48+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/webhook/issues>`_.
49+
In case of trouble, please check there if your issue has already been reported.
50+
If you spotted it first, help us to smash it by providing a detailed and welcomed
51+
`feedback <https://github.com/OCA/webhook/issues/new?body=module:%20webhook_incoming%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
52+
53+
Do not contact contributors directly about support or help with technical issues.
54+
55+
Credits
56+
=======
57+
58+
Authors
59+
~~~~~~~
60+
61+
* Hoang Tran
62+
63+
Contributors
64+
~~~~~~~~~~~~
65+
66+
* Hoang Tran <thhoang.tr@gmail.com>
67+
68+
Maintainers
69+
~~~~~~~~~~~
70+
71+
This module is maintained by the OCA.
72+
73+
.. image:: https://odoo-community.org/logo.png
74+
:alt: Odoo Community Association
75+
:target: https://odoo-community.org
76+
77+
OCA, or the Odoo Community Association, is a nonprofit organization whose
78+
mission is to support the collaborative development of Odoo features and
79+
promote its widespread use.
80+
81+
This module is part of the `OCA/webhook <https://github.com/OCA/webhook/tree/16.0/webhook_incoming>`_ project on GitHub.
82+
83+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

webhook_incoming/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import models
2+
from . import controllers

webhook_incoming/__manifest__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2024 Hoang Tran <thhoang.tr@gmail.com>.
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
3+
4+
{
5+
"name": "Incoming Webhook",
6+
"summary": "Receive incoming webhook requests as trigger to execute tasks.",
7+
"version": "16.0.0.0.1",
8+
"author": "Hoang Tran,Odoo Community Association (OCA)",
9+
"license": "LGPL-3",
10+
"website": "https://github.com/OCA/webhook",
11+
"depends": ["base_automation", "webhook_outgoing", "queue_job"],
12+
"data": [
13+
"views/base_automation_views.xml",
14+
],
15+
"auto_install": True,
16+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import main
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright 2024 Hoang Tran <thhoang.tr@gmail.com>.
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
3+
from odoo.http import Controller, request, route
4+
5+
6+
def get_webhook_request_payload():
7+
if not request:
8+
return None
9+
try:
10+
payload = request.get_json_data()
11+
except ValueError:
12+
payload = {**request.httprequest.args}
13+
return payload
14+
15+
16+
class BaseAutomationController(Controller):
17+
@route(
18+
["/web/hook/<string:rule_uuid>"],
19+
type="http",
20+
auth="public",
21+
methods=["GET", "POST"],
22+
csrf=False,
23+
save_session=False,
24+
)
25+
def call_webhook_http(self, rule_uuid, **kwargs):
26+
"""Execute an automation webhook"""
27+
rule = (
28+
request.env["base.automation"]
29+
.sudo()
30+
.search([("webhook_uuid", "=", rule_uuid)])
31+
)
32+
if not rule:
33+
return request.make_json_response({"status": "error"}, status=404)
34+
35+
data = get_webhook_request_payload()
36+
try:
37+
rule._execute_webhook(data)
38+
except Exception: # noqa: BLE001
39+
return request.make_json_response({"status": "error"}, status=500)
40+
return request.make_json_response({"status": "ok"}, status=200)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import base_automation
2+
from . import ir_actions_server

0 commit comments

Comments
 (0)