commit 5a2aef8
grunfink
·
2025-05-30 10:12:19 +0000 UTC
parent c8f6e18
More notify_webhook work.
2 files changed,
+43,
-1
M
data.c
+33,
-0
1@@ -2765,6 +2765,39 @@ void process_user_queue_item(snac *user, xs_dict *q_item)
2 snac_log(user, xs_fmt("actor_refresh %s %d", actor, status));
3 }
4 }
5+ else
6+ if (strcmp(type, "notify_webhook") == 0) {
7+ const char *webhook = xs_dict_get(user->config, "notify_webhook");
8+
9+ if (xs_is_string(webhook)) {
10+ const xs_dict *msg = xs_dict_get(q_item, "message");
11+ int retries = xs_number_get(xs_dict_get(q_item, "retries"));
12+
13+ xs *hdrs = xs_dict_new();
14+
15+ hdrs = xs_dict_set(hdrs, "content-type", "application/json");
16+ hdrs = xs_dict_set(hdrs, "user-agent", USER_AGENT);
17+
18+ xs *body = xs_json_dumps(msg, 4);
19+
20+ int status;
21+ xs *rsp = xs_http_request("POST", webhook, hdrs, body, strlen(body), &status, NULL, NULL, 0);
22+
23+ snac_debug(user, 0, xs_fmt("webhook post %s %d", webhook, status));
24+
25+ if (!valid_status(status)) {
26+ retries++;
27+
28+ if (retries > queue_retry_max)
29+ snac_debug(user, 0, xs_fmt("webhook post giving up %s", webhook));
30+ else {
31+ snac_debug(user, 0, xs_fmt("webhook post requeue %s %d", webhook, retries));
32+
33+ enqueue_notify_webhook(user, msg, retries);
34+ }
35+ }
36+ }
37+ }
38 else
39 snac_log(user, xs_fmt("unexpected user q_item type '%s'", type));
40 }
M
data.c
+10,
-1
1@@ -3529,7 +3529,16 @@ void enqueue_notify_webhook(snac *user, const xs_dict *noti, int retries)
2 const char *webhook = xs_dict_get(user->config, "notify_webhook");
3
4 if (xs_is_string(webhook)) {
5- xs *qmsg = _new_qmsg("notify_webhook", noti, retries);
6+ xs *msg = xs_dup(noti);
7+
8+ /* add more data */
9+ msg = xs_dict_set(msg, "target", user->actor);
10+ xs *actor_obj = NULL;
11+
12+ if (valid_status(object_get(xs_dict_get(noti, "actor"), &actor_obj)) && actor_obj)
13+ msg = xs_dict_set(msg, "account", actor_obj);
14+
15+ xs *qmsg = _new_qmsg("notify_webhook", msg, retries);
16 const char *ntid = xs_dict_get(qmsg, "ntid");
17 xs *fn = xs_fmt("%s/queue/%s.json", user->basedir, ntid);
18