Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webhook #503

Open
doko89 opened this issue Aug 22, 2024 · 18 comments
Open

webhook #503

doko89 opened this issue Aug 22, 2024 · 18 comments
Labels
help wanted Extra attention is needed

Comments

@doko89
Copy link

doko89 commented Aug 22, 2024

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
Copy link
Owner

ellite commented Aug 23, 2024

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}}"
  }

@ellite ellite added the help wanted Extra attention is needed label Aug 23, 2024
@PDxtXHd
Copy link

PDxtXHd commented Aug 30, 2024

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
Copy link
Owner

ellite commented Aug 30, 2024

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
Copy link

PDxtXHd commented Aug 30, 2024

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
Copy link
Owner

ellite commented Aug 30, 2024

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
Copy link

PDxtXHd commented Aug 30, 2024

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
Copy link
Owner

ellite commented Aug 30, 2024

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
Copy link

PDxtXHd commented Aug 30, 2024

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
Copy link
Owner

ellite commented Aug 30, 2024

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

@PDxtXHd
Copy link

PDxtXHd commented Aug 30, 2024

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
Copy link

PDxtXHd commented Aug 30, 2024

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
Copy link
Owner

ellite commented Aug 30, 2024

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
Copy link

PDxtXHd commented Aug 30, 2024

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
Copy link
Owner

ellite commented Sep 1, 2024

Hi, I believe someone posted the solution to your issue on this discussion: #383

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

Please try it and let me know.
Regards.

@PDxtXHd
Copy link

PDxtXHd commented Sep 2, 2024

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
Copy link
Owner

ellite commented Sep 2, 2024

Awesome! Glad it's working.

@allmors
Copy link

allmors commented Sep 14, 2024

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

@latetedemelon
Copy link

If it helps anyone I wrote up the following on how to configure webhooks.

  1. Access Webhook Settings:

    • Navigate to the Wallos dashboard.
    • Go to the Settings section.
    • Locate the Notifications or Webhooks configuration area.
  2. Set Up the Webhook:

    • Webhook URL: Enter the URL of the service you want Wallos to send notifications to.
    • HTTP Method: Choose the appropriate method (POST or GET) as required by your target service.
    • Payload: Define the data structure to be sent. Wallos allows the use of variables to customize the message content.
  3. Utilize Available Variables:
    Wallos supports the following variables for dynamic content in your webhook payload:

    • {{days_until}}: Days until the next payment.
    • {{subscription_name}}: Name of the subscription.
    • {{subscription_price}}: Price of the subscription.
    • {{subscription_currency}}: Currency of the subscription.
    • {{subscription_category}}: Category of the subscription.
    • {{subscription_date}}: Next payment date of the subscription.
    • {{subscription_payer}}: Name of the payer.
    • {{subscription_days_until_payment}}: Days until the subscription payment is due.
    • {{subscription_notes}}: Additional notes related to the subscription.
    • {{subscription_url}}: URL associated with the subscription.
  4. Example Payload:
    To send a notification via a WhatsApp gateway, you might structure your payload as follows:

    {
      "phone": "12345",
      "message": "Hi {{subscription_payer}}, your subscription to {{subscription_name}} is due in {{days_until}} days. The amount is {{subscription_currency}}{{subscription_price}}. For more details, visit {{subscription_url}}."
    }
  5. Set Custom Headers (Optional):
    Depending on the requirements of your target service, you may need to set custom HTTP headers:

    • Authorization: Include tokens or API keys required by the receiving service.
      • Example: Authorization: Bearer YOUR_ACCESS_TOKEN
    • Content-Type: Specify the format of the payload to ensure the receiving service processes it correctly.
      • Example: Content-Type: application/json
    • User-Agent: Identify the source of the webhook request.
      • Example: User-Agent: Wallos-Webhook/1.0
    • Custom Verification Headers: Implement headers that the receiving service can use to verify the authenticity of the request.
      • Example: X-Wallos-Signature: SIGNATURE_HASH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants