Skip to content

Conversation

@rafaelmf3
Copy link
Contributor

@rafaelmf3 rafaelmf3 commented Jan 15, 2026

Add Campaign Feature Support to Java SDK

Summary

This PR adds complete campaign feature support to the stream-chat-java SDK, matching the Python SDK implementation. All 7 backend campaign routes are now fully implemented and tested.

Backend Routes Implemented

  • POST /campaigns - Create campaign
  • GET /campaigns/{id} - Get campaign by ID
  • PUT /campaigns/{id} - Update campaign
  • DELETE /campaigns/{id} - Delete campaign
  • POST /campaigns/{id}/start - Start campaign (with optional scheduling)
  • POST /campaigns/{id}/stop - Stop campaign
  • POST /campaigns/query - Query campaigns with filters and sorting

Changes

New Files

  • src/main/java/io/getstream/chat/java/services/CampaignService.java - Retrofit service interface

    • All 7 campaign endpoint methods with proper Retrofit annotations
    • Follows existing service patterns (CommandService, ChannelService)
  • src/main/java/io/getstream/chat/java/models/Campaign.java - Campaign model class

    • Main Campaign class with all fields (id, name, description, senderId, status, etc.)
    • Nested data structures: MessageTemplate, MemberTemplate, ChannelTemplate
    • Request data classes with @Builder pattern for all operations
    • Request classes extending StreamRequest<T> for all operations
    • Response classes extending StreamResponseObject for all operations
    • Static factory methods: create(), get(), update(), delete(), start(), stop(), query()

Test Files

  • src/test/java/io/getstream/chat/java/CampaignTest.java - Comprehensive JUnit 5 tests covering:
    • Campaign creation (with and without ID)
    • Full CRUD operations
    • Start/stop with scheduling
    • Query campaigns with filters and sorting
    • Proper cleanup in all tests

Features

  • Fluent API: Builder pattern for request construction
  • Type Safety: Proper use of @NotNull and @Nullable annotations
  • JSON Mapping: Jackson annotations for proper serialization/deserialization
  • DateTime Support: Date type for scheduled_for and stop_at parameters
  • Query Support: Full filter conditions, sorting, and pagination using FilterCondition and Sort utilities
  • Lombok Integration: Uses @Data, @Builder, @Getter, @EqualsAndHashCode for boilerplate reduction

Code Quality

  • ✅ All code follows Java SDK patterns (Command model pattern)
  • ✅ Proper Lombok annotations usage
  • ✅ All request/response classes properly extend base classes
  • ✅ Comprehensive unit tests with proper cleanup
  • ✅ No linting errors in new code
  • ✅ Follows existing naming conventions and code style

Testing

All campaign tests pass successfully:

  • Campaign creation (with and without ID)
  • Full CRUD operations
  • Start/stop with scheduling
  • Query campaigns with filters
  • Proper test cleanup

Example Usage

// Create a campaign

MessageTemplate messageTemplate = new MessageTemplate();
messageTemplate.setText("Hello");

Campaign campaign = Campaign.create()
    .senderId("user-1")
    .userIds(List.of("user-2"))
    .messageTemplate(messageTemplate)
    .name("My Campaign")
    .request()
    .getCampaign();

// Get a campaign

Campaign retrieved = Campaign.get(campaignId)
    .request()
    .getCampaign();

// Update a campaign

Campaign updated = Campaign.update(campaignId)
    .name("Updated Name")
    .messageTemplate(messageTemplate)
    .senderId("user-1")
    .userIds(List.of("user-2"))
    .request()
    .getCampaign();

// Start a campaign with scheduling

Calendar cal = Calendar.getInstance();
cal.add(Calendar.HOUR, 1);
Date scheduledFor = cal.getTime();

Campaign started = Campaign.start(campaignId)
    .scheduledFor(scheduledFor)
    .stopAt(stopAt)
    .request()
    .getCampaign();

// Stop a campaign

Campaign stopped = Campaign.stop(campaignId)
    .request()
    .getCampaign();

// Query campaigns

List<Campaign> campaigns = Campaign.query()
    .filter(FilterCondition.eq("id", campaignId))
    .sorts(List.of(Sort.builder()
        .field("created_at")
        .direction(Sort.Direction.DESC)
        .build()))
    .limit(10)
    .request()
    .getCampaigns();

// Delete a campaign
Campaign.delete(campaignId).request();

CLA

  • I have signed the Stream CLA (required).
  • The code changes follow best practices
  • Code changes are tested (add some information if not applicable)

Description of the pull request

@rafaelmf3 rafaelmf3 self-assigned this Jan 15, 2026
@shaljam shaljam merged commit c9979b5 into main Jan 16, 2026
1 check passed
@shaljam shaljam deleted the cha-1427-support-campaigns branch January 16, 2026 10:18
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