diff options
| author | 2025-05-30 12:12:19 +0200 | |
|---|---|---|
| committer | 2025-05-30 12:12:19 +0200 | |
| commit | 5a2aef8666a82a30dff329992bd41baa53d4e123 (patch) | |
| tree | bf64325bf2f2bed44567484563775e9e2fc5296f /activitypub.c | |
| parent | New function enqueue_notify_webhook(). (diff) | |
| download | snac2-5a2aef8666a82a30dff329992bd41baa53d4e123.tar.gz snac2-5a2aef8666a82a30dff329992bd41baa53d4e123.tar.xz snac2-5a2aef8666a82a30dff329992bd41baa53d4e123.zip | |
More notify_webhook work.
Diffstat (limited to 'activitypub.c')
| -rw-r--r-- | activitypub.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/activitypub.c b/activitypub.c index 8877a27..fb0c42c 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -2766,6 +2766,39 @@ void process_user_queue_item(snac *user, xs_dict *q_item) | |||
| 2766 | } | 2766 | } |
| 2767 | } | 2767 | } |
| 2768 | else | 2768 | else |
| 2769 | if (strcmp(type, "notify_webhook") == 0) { | ||
| 2770 | const char *webhook = xs_dict_get(user->config, "notify_webhook"); | ||
| 2771 | |||
| 2772 | if (xs_is_string(webhook)) { | ||
| 2773 | const xs_dict *msg = xs_dict_get(q_item, "message"); | ||
| 2774 | int retries = xs_number_get(xs_dict_get(q_item, "retries")); | ||
| 2775 | |||
| 2776 | xs *hdrs = xs_dict_new(); | ||
| 2777 | |||
| 2778 | hdrs = xs_dict_set(hdrs, "content-type", "application/json"); | ||
| 2779 | hdrs = xs_dict_set(hdrs, "user-agent", USER_AGENT); | ||
| 2780 | |||
| 2781 | xs *body = xs_json_dumps(msg, 4); | ||
| 2782 | |||
| 2783 | int status; | ||
| 2784 | xs *rsp = xs_http_request("POST", webhook, hdrs, body, strlen(body), &status, NULL, NULL, 0); | ||
| 2785 | |||
| 2786 | snac_debug(user, 0, xs_fmt("webhook post %s %d", webhook, status)); | ||
| 2787 | |||
| 2788 | if (!valid_status(status)) { | ||
| 2789 | retries++; | ||
| 2790 | |||
| 2791 | if (retries > queue_retry_max) | ||
| 2792 | snac_debug(user, 0, xs_fmt("webhook post giving up %s", webhook)); | ||
| 2793 | else { | ||
| 2794 | snac_debug(user, 0, xs_fmt("webhook post requeue %s %d", webhook, retries)); | ||
| 2795 | |||
| 2796 | enqueue_notify_webhook(user, msg, retries); | ||
| 2797 | } | ||
| 2798 | } | ||
| 2799 | } | ||
| 2800 | } | ||
| 2801 | else | ||
| 2769 | snac_log(user, xs_fmt("unexpected user q_item type '%s'", type)); | 2802 | snac_log(user, xs_fmt("unexpected user q_item type '%s'", type)); |
| 2770 | } | 2803 | } |
| 2771 | 2804 | ||