Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions docs/builtin-mailboxes-webhooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,32 @@ trigger:
| `orin@dtcdev.click` | `/hooks/webhook/orin` | `orin-mailbox` | Orin Grok bot webhook (or Orin sticky Hub session when GrokBot usage < 1%) |
| `freelancer@dtcdev.click` | `/hooks/webhook/freelancer` | `freelancer-mailbox` | Freelancer Grok bot webhook (or Freelancer sticky Hub session when GrokBot usage < 1%). Sender policy is `anyone` so Gmail-forwarded marketplace mail (Upwork, Fiverr, Contra, Malt, Freelancer.com) is accepted; wildcards are not supported on allowlists. |

### Personal Gmail marketplace watch (`freelancer-gmail`)

A second, read-only path covers the same marketplace mail without Gmail
forwarding or `gmail.settings.*` scopes. Poll trigger `freelancer-gmail`
(`polls/freelancer-gmail.json`) watches Alexey's personal Gmail through the
existing `google-calendar` connection (`gmail.readonly`). The query is:

```
from:(upwork.com OR fiverr.com OR contra.com OR malt.com OR malt.de OR freelancer.com)
```

`gmail.messages` already seeds its `internalDate` watermark on the first
fire (existing mail is history, not news) and dedupes by message id. The
poll only lists and reads messages; it never changes labels, archives,
deletes, or sends. `freelancer-mailbox` also triggers on
`gmail` / `message.received` with `poll: { equals: freelancer-gmail }` and
posts the same webhook payload (`from`, `subject`, `body` / `snippet` /
`text`, `thread_link`).

```bash
dapier polls save polls/freelancer-gmail.json
dapier polls check freelancer-gmail # first check seeds the watermark
dapier polls show freelancer-gmail # expect starts: freelancer-mailbox
```


Notify path: `dev-mailbox` classifies every dev@ mail and always posts it to
the direct oncall ingest at `https://hub.dtcdev.click/webhooks/oncall`. The
direct receiver is Hub2, a Node server on the GCP VM with a durable SQLite
Expand Down
8 changes: 8 additions & 0 deletions polls/freelancer-gmail.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "freelancer-gmail",
"description": "Readonly watch of marketplace mail in Alexey's personal Gmail (connection google-calendar = alexey.s.grigoriev@gmail.com). First fire seeds the watermark at now and emits nothing (no backfill). Later fires emit messages delivered after that watermark; the seen store dedupes by Gmail message id. messages.list/get only — no labels, deletes, archives, or sends. Starts freelancer-mailbox.",
"expression": "rate(1 minute)",
"source": "gmail.messages",
"connection_id": "google-calendar",
"query": "from:(upwork.com OR fiverr.com OR contra.com OR malt.com OR malt.de OR freelancer.com)"
}
87 changes: 87 additions & 0 deletions tests/test_dev_mailbox_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,93 @@ def test_freelancer_mailbox_extracts_platform_thread_link():
assert result["thread_link"] == "https://www.upwork.com/ab/messages/rooms/room_123"


def test_freelancer_mailbox_has_scoped_gmail_poll_trigger():
_, wf = _load("freelancer-mailbox")
gmail = next((tr for tr in wf["triggers"] if tr.get("connector") == "gmail"), None)
assert gmail is not None
assert gmail["event"] == "message.received"
assert gmail["filters"]["poll"]["equals"] == "freelancer-gmail"
# Must not accept every gmail poll: bound_workflows treats a missing
# poll filter as "all polls of this connector".
assert list(gmail["filters"]) == ["poll"]
types = [a.get("type") for a in _iter_steps(wf)]
assert "gmail_send" not in types
assert not any(t.startswith("gmail_") and t != "gmail_send" for t in types if t)


def test_freelancer_mailbox_matches_gmail_poll_event():
_, wf = _load("freelancer-mailbox")
event = {
"connector": "gmail",
"event": "message.received",
"source": "freelancer-gmail",
"data": {
"poll": "freelancer-gmail",
"id": "msg-abc",
"item_id": "msg-abc",
"from": "notifications@upwork.com",
"to": "alexey.s.grigoriev@gmail.com",
"subject": "You have a new offer",
"text": "See https://www.upwork.com/ab/messages/rooms/room_9",
"snippet": "See https://www.upwork.com/ab/messages/rooms/room_9",
},
}
assert matching.matches(wf, event) is True
other = dict(event, data={**event["data"], "poll": "some-other-gmail-poll"})
assert matching.matches(wf, other) is False


def test_freelancer_mailbox_formats_gmail_poll_payload():
_, wf = _load("freelancer-mailbox")
code_action = next(a for a in wf["actions"] if a.get("type") == "code")
text = "New offer: https://www.fiverr.com/inbox/thread/42 please review."
event = {
"connector": "gmail",
"data": {
"id": "18f00gmailid",
"thread_id": "18f00thread",
"from": "Fiverr <noreply@fiverr.com>",
"to": "alexey.s.grigoriev@gmail.com",
"subject": "You have a new message",
"date": "Sun, 29 Nov 2026 11:00:00 +0100",
"snippet": "New offer: https://www.fiverr.com/inbox/thread/42",
"text": text,
"poll": "freelancer-gmail",
},
}
result = run_code(code_action, event)["result"]
assert result["from"] == "Fiverr <noreply@fiverr.com>"
assert result["to"] == "alexey.s.grigoriev@gmail.com"
assert result["subject"] == "You have a new message"
assert result["message_id"] == "18f00gmailid"
assert result["text"] == text
assert result["body"] == text
assert result["thread_link"] == "https://www.fiverr.com/inbox/thread/42"
assert result["snippet"] == " ".join(text.split())[:200]


def test_freelancer_gmail_poll_definition():
import json
from src.dapier.triggers import poll_triggers, poll_sources
body = json.loads((Path(__file__).parent.parent / "polls/freelancer-gmail.json").read_text())
assert body["name"] == "freelancer-gmail"
assert body["source"] == "gmail.messages"
assert body["connection_id"] == "google-calendar"
assert body["expression"] == "rate(1 minute)"
assert "upwork.com" in body["query"]
assert "fiverr.com" in body["query"]
assert "contra.com" in body["query"]
assert "malt.com" in body["query"]
assert "malt.de" in body["query"]
assert "freelancer.com" in body["query"]
assert "actions" not in body
item = poll_triggers.build_item(body, "op@example.test")
assert item["poll_id"] == "freelancer-gmail"
assert item["source"] == "gmail.messages"
spec = poll_sources.resolve(item["source"])
assert (spec.connector, spec.event) == ("gmail", "message.received")


def test_dev_mailbox_code_action_payload_formatting():
wf_path = Path(__file__).parent.parent / "workflows/dev-mailbox.yaml"
wf = yaml.safe_load(wf_path.read_text())
Expand Down
13 changes: 10 additions & 3 deletions workflows/freelancer-mailbox.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
id: freelancer-mailbox
enabled: true
description: Freelancer mailbox freelancer@dtcdev.click -> Freelancer Grok bot webhook, or Freelancer sticky Hub session when GrokBot remaining usage < 1%
description: Freelancer mailbox freelancer@dtcdev.click, and marketplace mail in Alexey's personal Gmail via the readonly freelancer-gmail poll, -> Freelancer Grok bot webhook, or Freelancer sticky Hub session when GrokBot remaining usage < 1%
triggers:
- connector: email
event: message.received
Expand All @@ -12,6 +12,11 @@ triggers:
filters:
hook:
equals: freelancer
- connector: gmail
event: message.received
filters:
poll:
equals: freelancer-gmail
actions:
- id: get-url
type: storage_get
Expand Down Expand Up @@ -91,7 +96,7 @@ actions:

subject = input.get("subject") or hook_body.get("subject") or ""
date = input.get("date") or hook_body.get("date") or ""
message_id = input.get("message_id") or hook_body.get("message_id") or ""
message_id = input.get("message_id") or hook_body.get("message_id") or input.get("id") or ""

body = input.get("body") or {}
text = ""
Expand All @@ -107,6 +112,8 @@ actions:
text = input.get("text").get("value") or input.get("text").get("text") or ""
if not text and hook_body.get("text"):
text = str(hook_body.get("text"))
if not text and input.get("snippet"):
text = str(input.get("snippet"))

snippet = " ".join(str(text).split())
snippet = snippet[:200]
Expand All @@ -125,7 +132,7 @@ actions:
if any(host == h or host.endswith("." + h) for h in PLATFORM_HOSTS):
return url.rstrip(").,];>")
return ""
thread_link = _thread_link(text)
thread_link = _thread_link(text) or _thread_link(input.get("snippet"))

attachments = []
for att in (input.get("attachments") or hook_body.get("attachments") or []):
Expand Down
Loading