ellite / Wallos

Wallos: Open-Source Personal Subscription Tracker
GNU General Public License v3.0
2.48k stars 113 forks source link

webhook #503

Open doko89 opened 3 weeks ago

doko89 commented 3 weeks ago

can anyone help me? I have simple whatsapp gateway how to setting wallos webhook payload

my whatsapp gateway template payload

{
  "phone": "12345",
  "message": "notif from wallos"
}
ellite commented 3 weeks ago

You need to build the message using the available variables:

Variables available: {{days_until}}, {{subscription_name}}, {{subscription_price}}, {{subscription_currency}}, {{subscription_category}}, {{subscription_date}}, {{subscription_payer}}, {{subscription_days_until_payment}}

You can try something like:

  {
    "phone": "12345",
    "message": "Hi {{subscription_payer}}, {{subscription_name}} is up for payment in {{subscription_days_until_payment}} for {{subscription_currency}}{{subscription_price}}"
  }
PDxtXHd commented 2 weeks ago

Hi @ellite ,I want to know the format of customheaders in webhook. I tried 'Content-Type': 'application/json' and 'Content-Type: application/json' and even json, but non of them worked for me. I'm sure this is the source of problem because I can use curl to send the webhook notification successfully

ellite commented 2 weeks ago

Hi.

Custom headers it's an optional field.

But this is what I use to bypass cloudflare authentication using cloudflare tunnels.

{
    "CF-Access-Client-Id": "myClientId",
    "CF-Access-Client-Secret": "myClientSecret"
}

But in most cases you should not need custom headers.

PDxtXHd commented 2 weeks ago

Hi @ellite Thanks for your reply. I have to use custom headers becuse otherwise the remote server may not recognize json format. But I may need more help. I can use this curl command to succesfully send the webhook notification via the server

curl -X POST -H "Content-Type: application/json" -d '{"text": "test reminder", "desp": "content"}' https://iyuu.cn/IYUUkey.send

But when I input like this in wallos, it dosen't work. Screenshot

Custom header is

{
    "Content-Type": "application/json"
}

and I tried

{"text": "test reminder", "desp": "content"}

and

{
    "text": "test reminder",
    "desp": "content"
}

Is there any thing wrong?

ellite commented 2 weeks ago

On Wallos side:

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $requestmethod);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
if (!empty($customheaders)) {
    curl_setopt($ch, CURLOPT_HTTPHEADER, $customheaders);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

So, to get exactly curl -X POST -H "Content-Type: application/json" -d '{"text": "test reminder", "desp": "content"}' https://iyuu.cn/IYUUkey.send

I believe you need to remove the { } from the custom headers and set only: Content-Type: application/json

PDxtXHd commented 2 weeks ago

On Wallos side:

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $requestmethod);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
if (!empty($customheaders)) {
    curl_setopt($ch, CURLOPT_HTTPHEADER, $customheaders);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

So, to get exactly curl -X POST -H "Content-Type: application/json" -d '{"text": "test reminder", "desp": "content"}' https://iyuu.cn/IYUUkey.send

I believe you need to remove the { } from the custom headers and set only: Content-Type: application/json

Still doesn't work, wallos gives me a successfully sent toast, but nothing received. image

Is there a way to see the log so that I can see the response of remote server?

ellite commented 2 weeks ago

Strange. Assuming your container is called "wallos" you can try:

docker exec -it wallos sh

then inside the container:

apk add nano nano /var/www/html/endpoints/notifications/testwebhooknotifications.php

and after this block of code:

// Execute the request
$response = curl_exec($ch);

add:

echo $response;

ctrl + x to save and exit

then try again with the developer tools open on your browser on the network tab. the response of the endpoint should now include the response of the curl call.

PDxtXHd commented 2 weeks ago

Strange. Assuming your container is called "wallos" you can try:

docker exec -it wallos sh

then inside the container:

apk add nano nano /var/www/html/endpoints/notifications/testwebhooknotifications.php

and after this block of code:

// Execute the request
$response = curl_exec($ch);

add:

echo $response;

ctrl + x to save and exit

then try again with the developer tools open on your browser on the network tab. the response of the endpoint should now include the response of the curl call.

The response is

{"errcode":400,"errmsg":"text不能为空","data":[]}{"success":true,"message":"\u901a\u77e5\u5df2\u6210\u529f\u53d1\u9001"}

The response is the same as when I don't specify Content-Type: application/json in the curl command when testing in the terminal image but it's weired since i can see the content-type in request headers image

ellite commented 2 weeks ago

It seems to me to be related with the peyload instead? Isn't the error message stating that the text field is empty?

PDxtXHd commented 2 weeks ago

It seems to me to be related with the peyload instead? Isn't the error message stating that the text field is empty?

The meaning is that the text field is empty, but as long as I specify the content-type to be json, it works fine. So I still think the problem is headers. Maybe the server can't parse json unless the format is specified? image

PDxtXHd commented 2 weeks ago

I tried another server, https://sctapi.ftqq.com/key.send Almost the same result: When tested in curl, specified content-type works fine, while not specified content-type fails: image The response means empty tile, since the payload structure is

{
    "title": "test reminder",
    "desp": "content"
}

And in wallos also the same: image

ellite commented 2 weeks ago

It must be some bug in the code then. No idea what it might be. But I'll have a look when I have some time.

Thank you for all the details.

PDxtXHd commented 2 weeks ago

It must be some bug in the code then. No idea what it might be. But I'll have a look when I have some time.

Thank you for all the details.

Thanks for your work!

ellite commented 2 weeks ago

Hi, I believe someone posted the solution to your issue on this discussion: https://github.com/ellite/Wallos/discussions/383

You should set the custom headers as: ["Content-Type: application/json"]

Please try it and let me know. Regards.

PDxtXHd commented 2 weeks ago

Hi @ellite , I think ["Content-Type: application/json"] works for me. I tested several times using the 2 remote servers mentioned above, all sent succesfully. Thank you for your help!

ellite commented 2 weeks ago

Awesome! Glad it's working.

allmors commented 2 days ago

Awesome! Glad it's working.

Awesome! Glad it's working.

What should the webhookbody look like?

{
    "title": "any text",
    "{{subscriptions}}": "Hi {{subscription_payer}}, {{subscription_name}} is up for payment in {{subscription_days_until_payment}} for {{subscription_currency}}{{subscription_price}}",
    "device_key": "JnJ5Ft**********PAvFkF",
    "badge": 1,
    "sound": "minuet.caf",
    "icon": "https://day.app/assets/images/avatar.jpg",
    "group": "test",
    "url": "https://github.com/Finb"
}

replace subscriptions value

body

Is it like the above? I use bark, but the body content is empty