コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
1605 ビュー


I want to show my new module under "Coba Idea" module.

I want to experiment with webhook, here is my code for both the .py and .xml

.py :


class MyWebhook(models.Model):
​_name = 'webhook.webhook'
​_description = "Coba Webhook"

​payload = fields.Text("Payload")

@http.route('/webhook', type='http', methods=['POST'], auth="none")
def webhook_listen(self, **kwargs):
result = {'success': _("Data get")}
try:
wh= self.env['webhook.webhook'].create({
'payload': kwargs.get('message')
})
result = {'success': _("Data Saved")}
except Exception as e:
logger.exception("Fail to save data %s", kwargs.get('message'))
result = {'error': str(e)}

return json.dumps(result)



Tried the webhook with curl,

curl -i -X POST -d "ok" http://localhost:8068/webhook



Thanks

アバター
破棄
著作者 最善の回答

Turns out, 

The class should use http.Controller instead of models.Model :

class MyWebhook(http.Controller):

​code here

アバター
破棄