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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ All notable changes to this project are documented here. The format follows
`CustomConversionRule`.
- `UploadConversionsParams` events accept `eventId`, `actionSource`, `sourceUrl`, `externalId`,
`clientIpAddress`, `clientUserAgent`, `clickId`, `browserId` and `contentIds` through `with`.
- `inbox().resolve(InboxResolveParams)` resolves every unanswered item of one type in bulk,
optionally only on some accounts (`accountId`) or only items dated `before` an instant, and
returns how many changed. Nothing reaches a platform. Needs `inbox`.
- `InboxListParams` and `InboxThreadParams` take `status` (`unanswered`, `replied`, `resolved`)
and `since`, and `accountId` takes one or more ids (or `accountIds(List)`), sent comma-separated.

### Changed

Expand All @@ -34,6 +39,9 @@ All notable changes to this project are documented here. The format follows

### Removed

- `InboxListParams` and `InboxThreadParams` drop `state`, `platform` and `q`, and `sort` no longer
takes `unanswered`; the inbox list endpoints no longer read them. Filter by `status` and
`accountId` instead.
- `blog()` (`BlogResource`) and the retired `/v1/blog/*` endpoints it wrapped (settings,
website secret and test, destinations, keywords, articles), with `BlogParams`, every `Blog*`
model and constant class, and `WebhookEvents.ARTICLE_PUBLISHED`. Articles are ordinary posts
Expand Down
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,19 +300,31 @@ Comments, mentions and direct messages across the connected accounts, with the s
(`unread`, `read`, `resolved`, `snoozed`). Lists are pages with `page`, `perPage` and `total`.

```java
InboxPage<InboxItem> unread = client.inbox().list(
InboxListParams.create().workspaceId(workspace.id()).state("unread"));

for (InboxItem item : unread) {
InboxPage<InboxItem> unanswered = client.inbox().list(
InboxListParams.create()
.workspaceId(workspace.id())
.accountId(instagramId, facebookId)
.status("unanswered")
.since(Instant.parse("2026-09-01T00:00:00Z")));

for (InboxItem item : unanswered) {
if (Boolean.TRUE.equals(item.canReply())) {
client.inbox().reply(item.id(), "Thanks for asking, sent you a DM.");
}
}

client.inbox().markThreadRead(workspace.id(), accountId, postExternalId);
client.inbox().update(itemId, "snoozed", Instant.parse("2026-09-02T09:00:00Z"));

// Resolve every unanswered comment older than a week, without replying.
int resolved = client.inbox().resolve(InboxResolveParams.of(workspace.id(), "comment")
.before(Instant.now().minus(Duration.ofDays(7))));
```

`status` is `unanswered`, `replied` or `resolved` (a reply also resolves an item), `since` keeps
items the platform dates at or after an instant, `accountId` takes one or more accounts, and
`sort` is `newest` or `oldest`. The same filters apply to `threads` and `conversations`.

`threads` groups comments per platform post (`kind("mentions")` for posts the account was tagged
in) and `conversations` per DM thread. `listApprovals` returns replies an automation or the agent
drafted that a person still has to send; `approveReply` sends the draft (or your edited text) and
Expand Down
45 changes: 31 additions & 14 deletions src/main/java/com/fopost/sdk/param/InboxListParams.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.fopost.sdk.param;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/** Filters for listing inbox items. Every field is optional. */
Expand All @@ -18,25 +22,43 @@ public InboxListParams workspaceId(String workspaceId) {
return this;
}

/** {@code comment}, {@code mention} or {@code dm}. */
/** {@code comment}, {@code mention}, {@code review} or {@code dm}. */
public InboxListParams type(String type) {
query.put("type", type);
return this;
}

/** {@code unread}, {@code read}, {@code resolved} or {@code snoozed}. */
public InboxListParams state(String state) {
query.put("state", state);
/** One or more connected accounts; sent comma-separated. */
public InboxListParams accountId(String... accountIds) {
return accountIds(accountIds == null ? null : Arrays.asList(accountIds));
}

public InboxListParams accountIds(List<String> accountIds) {
List<String> ids = new ArrayList<>();
if (accountIds != null) {
for (String id : accountIds) {
if (id != null && !id.isEmpty()) {
ids.add(id);
}
}
}
if (ids.isEmpty()) {
query.remove("account_id");
} else {
query.put("account_id", String.join(",", ids));
}
return this;
}

public InboxListParams platform(String platform) {
query.put("platform", platform);
/** {@code unanswered}, {@code replied} or {@code resolved}. A reply also resolves an item. */
public InboxListParams status(String status) {
query.put("status", status);
return this;
}

public InboxListParams accountId(String accountId) {
query.put("account_id", accountId);
/** Only items the platform dates at or after this instant. */
public InboxListParams since(Instant since) {
Params.put(query, "since", Params.iso(since));
return this;
}

Expand Down Expand Up @@ -64,12 +86,7 @@ public InboxListParams direction(String direction) {
return this;
}

public InboxListParams q(String q) {
query.put("q", q);
return this;
}

/** {@code newest}, {@code oldest} or {@code unanswered}. */
/** {@code newest} or {@code oldest}. */
public InboxListParams sort(String sort) {
query.put("sort", sort);
return this;
Expand Down
69 changes: 69 additions & 0 deletions src/main/java/com/fopost/sdk/param/InboxResolveParams.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.fopost.sdk.param;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
* What to resolve in bulk: every unanswered item of one type in a workspace, optionally only on
* some accounts or only items dated before an instant.
*
* <pre>{@code
* int resolved = client.inbox().resolve(InboxResolveParams.of(workspaceId, "comment")
* .before(Instant.now().minus(Duration.ofDays(7))));
* }</pre>
*/
public final class InboxResolveParams {

private final String workspaceId;
private final String type;
private final List<String> accountIds = new ArrayList<>();
private Instant before;

private InboxResolveParams(String workspaceId, String type) {
this.workspaceId = Objects.requireNonNull(workspaceId, "workspaceId");
this.type = Objects.requireNonNull(type, "type");
}

/** {@code type} is {@code comment}, {@code mention}, {@code review} or {@code dm}. */
public static InboxResolveParams of(String workspaceId, String type) {
return new InboxResolveParams(workspaceId, type);
}

/** Only these connected accounts. */
public InboxResolveParams accountId(String... accountIds) {
return accountIds(accountIds == null ? null : Arrays.asList(accountIds));
}

public InboxResolveParams accountIds(List<String> accountIds) {
if (accountIds != null) {
for (String id : accountIds) {
if (id != null && !id.isEmpty()) {
this.accountIds.add(id);
}
}
}
return this;
}

/** Only items the platform dates before this instant. */
public InboxResolveParams before(Instant before) {
this.before = before;
return this;
}

public Map<String, Object> toMap() {
Map<String, Object> body = new LinkedHashMap<>();
body.put("workspace_id", workspaceId);
body.put("type", type);
if (!accountIds.isEmpty()) {
body.put("account_id", new ArrayList<>(accountIds));
}
Params.put(body, "before", Params.iso(before));
return body;
}
}
39 changes: 28 additions & 11 deletions src/main/java/com/fopost/sdk/param/InboxThreadParams.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.fopost.sdk.param;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/** Filters for listing comment threads and DM conversations. Every field is optional. */
Expand All @@ -26,28 +30,41 @@ public InboxThreadParams kind(String kind) {
return this;
}

public InboxThreadParams platform(String platform) {
query.put("platform", platform);
return this;
/** One or more connected accounts; sent comma-separated. */
public InboxThreadParams accountId(String... accountIds) {
return accountIds(accountIds == null ? null : Arrays.asList(accountIds));
}

public InboxThreadParams accountId(String accountId) {
query.put("account_id", accountId);
public InboxThreadParams accountIds(List<String> accountIds) {
List<String> ids = new ArrayList<>();
if (accountIds != null) {
for (String id : accountIds) {
if (id != null && !id.isEmpty()) {
ids.add(id);
}
}
}
if (ids.isEmpty()) {
query.remove("account_id");
} else {
query.put("account_id", String.join(",", ids));
}
return this;
}

/** {@code unread}, {@code read}, {@code resolved} or {@code snoozed}. */
public InboxThreadParams state(String state) {
query.put("state", state);
/** {@code unanswered}, {@code replied} or {@code resolved}. A reply also resolves an item. */
public InboxThreadParams status(String status) {
query.put("status", status);
return this;
}

public InboxThreadParams q(String q) {
query.put("q", q);
/** Only items the platform dates at or after this instant. */
public InboxThreadParams since(Instant since) {
Params.put(query, "since", Params.iso(since));
return this;
}

/** {@code newest}, {@code oldest} or {@code unanswered}. */
/** {@code newest} or {@code oldest}. */
public InboxThreadParams sort(String sort) {
query.put("sort", sort);
return this;
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/com/fopost/sdk/resource/InboxResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.fopost.sdk.model.InboxThread;
import com.fopost.sdk.param.InboxListParams;
import com.fopost.sdk.param.InboxReplyParams;
import com.fopost.sdk.param.InboxResolveParams;
import com.fopost.sdk.param.InboxThreadParams;
import com.fopost.sdk.param.StartConversationParams;
import java.time.Instant;
Expand All @@ -30,9 +31,9 @@
* Comments, mentions, reviews and direct messages on the connected accounts.
*
* <pre>{@code
* InboxPage<InboxItem> unread = client.inbox().list(
* InboxListParams.create().workspaceId(workspaceId).state("unread"));
* for (InboxItem item : unread) {
* InboxPage<InboxItem> unanswered = client.inbox().list(
* InboxListParams.create().workspaceId(workspaceId).status("unanswered"));
* for (InboxItem item : unanswered) {
* if (Boolean.TRUE.equals(item.canReply())) {
* client.inbox().reply(item.id(), "Thanks for asking, sent you a DM.");
* }
Expand Down Expand Up @@ -138,6 +139,14 @@ public InboxRefreshResult refresh(String workspaceId) {
return http.convert(ApiClient.unwrap(http.post("/v1/inbox/refresh", body)), InboxRefreshResult.class);
}

/**
* Resolve every unanswered item of one type in bulk. Nothing reaches a platform. Returns how
* many items changed.
*/
public int resolve(InboxResolveParams params) {
return ApiClient.unwrap(http.post("/v1/inbox/resolve", params.toMap())).path("resolved").asInt(0);
}

/** {@code state} is unread, read or resolved. Snoozing needs {@link #update(String, String, Instant)}. */
public InboxItem update(String itemId, String state) {
return update(itemId, state, null);
Expand Down
46 changes: 44 additions & 2 deletions src/test/java/com/fopost/sdk/InboxTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.fopost.sdk.model.InboxReplyResult;
import com.fopost.sdk.param.InboxListParams;
import com.fopost.sdk.param.InboxReplyParams;
import com.fopost.sdk.param.InboxResolveParams;
import com.fopost.sdk.param.InboxThreadParams;
import com.fopost.sdk.param.StartConversationParams;
import java.time.Instant;
import java.util.List;
Expand All @@ -36,14 +38,17 @@ void listEncodesSnakeCaseFiltersAndReadsThePage() {
.inbox()
.list(InboxListParams.create()
.workspaceId("w1")
.state("unread")
.accountId("a1", "a2")
.status("unanswered")
.since(Instant.parse("2026-09-01T00:00:00Z"))
.postExternalId("ext-9")
.page(2)
.perPage(10));

assertEquals("GET", transport.last().method());
assertEquals(
"https://api.fopost.test/v1/inbox?workspace_id=w1&state=unread&post_external_id=ext-9&page=2&per_page=10",
"https://api.fopost.test/v1/inbox?workspace_id=w1&account_id=a1%2Ca2&status=unanswered"
+ "&since=2026-09-01T00%3A00%3A00Z&post_external_id=ext-9&page=2&per_page=10",
transport.last().url());
assertEquals(1, page.size());
InboxItem item = page.data().get(0);
Expand All @@ -55,6 +60,43 @@ void listEncodesSnakeCaseFiltersAndReadsThePage() {
assertEquals(2, page.meta().page());
}

@Test
void threadsSendTheStatusAndSortFilters() {
FakeTransport transport = new FakeTransport()
.enqueue(200, "{\"data\":[],\"meta\":{\"page\":1,\"perPage\":25,\"total\":0}}");

TestSupport.client(transport)
.inbox()
.threads(InboxThreadParams.create()
.kind("reviews")
.accountIds(List.of("a1"))
.status("replied")
.sort("oldest"));

assertEquals(
"https://api.fopost.test/v1/inbox/posts?kind=reviews&account_id=a1&status=replied&sort=oldest",
transport.last().url());
}

@Test
void resolvePostsTheTypeAccountsAndCutoff() {
FakeTransport transport = new FakeTransport().enqueue(200, "{\"data\":{\"resolved\":4}}");

int resolved = TestSupport.client(transport)
.inbox()
.resolve(InboxResolveParams.of("w1", "comment")
.accountId("a1", "a2")
.before(Instant.parse("2026-09-01T00:00:00Z")));

assertEquals("POST", transport.last().method());
assertEquals("https://api.fopost.test/v1/inbox/resolve", transport.last().url());
assertEquals(
"{\"workspace_id\":\"w1\",\"type\":\"comment\",\"account_id\":[\"a1\",\"a2\"],"
+ "\"before\":\"2026-09-01T00:00:00Z\"}",
transport.lastBody());
assertEquals(4, resolved);
}

@Test
void replyPostsTheTextAndUnwrapsTheResult() {
FakeTransport transport = new FakeTransport()
Expand Down
Loading