Skip to content

Conversation

@clabland
Copy link

@clabland clabland commented Dec 4, 2025

Add support for inbox messages. Sample snippet of how someone might use this in a NextJS app:

  // basic setup
  const [messages, setMessages] = useState<InboxMessage[]>([]);
  const [unreadCount, setUnreadCount] = useState(0);

  useEffect(() => {
    let unsubscribe: (() => void) | undefined;

    analytics.ready(async () => {
      const inbox = analytics.inbox();
      const initialMessages = await inbox.messages() || [];
      setMessages(initialMessages);
      setUnreadCount(await inbox.totalUnopened() || 0);
      unsubscribe = inbox.onUpdates(async (msgs: InboxMessage[]) => {
        setMessages(msgs || []);
        setUnreadCount(await inbox.totalUnopened() || 0);
      });
    });

    return () => {
      if (unsubscribe) {
        unsubscribe();
      }
    };
  }, []);

  // handling message states
  const handleToggleOpened = async (message: InboxMessage) => {
    try {
      if (message.opened) {
        await message.markUnopened();
      } else {
        await message.markOpened();
      }
    } catch (error) {
      console.error("Failed to toggle message opened state:", error);
    }
  };

  const handleDelete = async (message: InboxMessage) => {
    try {
      await message.markDeleted();
    } catch (error) {
      console.error("Failed to delete message:", error);
    }
  };

Note

Adds an Inbox API for in-app messages, exposes analytics.inbox(...topics) with counts/listeners/message controls, wires opened metric tracking, and bumps Gist SDK to 3.17.0.

  • In-App Plugin
    • Inbox API: New createInboxAPI providing total, totalUnopened, messages, onUpdates; InboxMessage supports markOpened/markUnopened/markDeleted with optional topic filtering.
    • Event handling: Listen to inboxMessageAction and track opened metrics; emit inbox updates via messageInboxUpdated.
    • Attach inbox(...topics) to analytics instance post-load.
  • Core
    • Expose analytics.inbox(...topics) on Analytics and buffered AnalyticsBuffered; add typings in core/analytics/interfaces.ts.
  • Dependencies
    • Bump customerio-gist-web to 3.17.0.

Written by Cursor Bugbot for commit 54a212b. This will update automatically on new commits. Configure here.

if (params?.message && params?.action !== '') {
_handleInboxMessageAction(_analytics, params.message, params.action)
}
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Incorrect condition allows undefined action values through

The condition params?.action !== '' incorrectly evaluates to true when params.action is undefined or null, since undefined !== '' and null !== '' both return true. This means _handleInboxMessageAction gets called with an undefined action value. While the function happens to guard against this in its own check (action === 'opened'), the condition doesn't match the apparent intent to only proceed when action is a non-empty string.

Fix in Cursor Fix in Web

@clabland clabland merged commit 359f395 into main Dec 15, 2025
5 checks passed
@clabland clabland deleted the INAPP-13667 branch December 15, 2025 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants