Skip to content
Download all docs .md

Chat System

The GameFuse Chat System allows you to implement real-time chat functionality in your game. This includes creating chats, sending messages, and managing message read status.

Getting Started with Chat

To use the GameFuse Chat system, you'll need to access the UGameFuseChat subsystem:

UGameFuseChat* ChatSystem = GetGameInstance()->GetSubsystem<UGameFuseChat>();

Creating a Chat

AI message filtering

If the game has AI message filtering on (game Settings tab, off by default), GameFuse checks every message with the Typesafe Jev decision model before saving it. This includes the first message of a new chat. The default rules block swearing, crude or sexual talk, racism and slurs; the developer can rewrite them. A message that breaks the rules is not saved: the callback reports failure (HTTP 422) and the error text starts with the error code message_rejected. If the developer is out of AI credits and chose to block, the code is message_filter_no_credits. The check costs the developer about $0.00006 per message from their AI credits and adds about a second.

You can create a new chat with one or more participants:

void UMyGameMode::CreateChat()
{
    UGameFuseChat* ChatSystem = GetGameInstance()->GetSubsystem<UGameFuseChat>();

    // Create an array of participant usernames
    TArray<FString> Usernames;
    Usernames.Add("OtherPlayerUsername"); // Add usernames of participants

    // Initial message to send
    FString InitialMessage = "Hello! Welcome to the chat.";

    // Create typed callback
    FGFChatCallback OnCreateChat;
    OnCreateChat.BindLambda([this](const FGFChat& Chat) {
        // Use Chat data (ID, participants, messages, etc.)
    });

    // Create the chat
    ChatSystem->CreateChat(Usernames, InitialMessage, OnCreateChat);
}

The typed callback only runs when the call works. Chat callbacks (FGFChatCallback, FGFMessageCallback, FGFChatListCallback, FGFMessageListCallback) are single delegates, so bind them with BindLambda or BindUObject.

The BP_ versions are the Blueprint nodes. You can also call them from C++ with the generic callback. The handler must be a UFUNCTION() that takes one FGFAPIResponse:

void UMyGameMode::CreateChatBP()
{
    UGameFuseChat* ChatSystem = GetGameInstance()->GetSubsystem<UGameFuseChat>();

    // Create an array of participant usernames
    TArray<FString> Usernames;
    Usernames.Add("OtherPlayerUsername"); // Add usernames of participants

    // Initial message to send
    FString InitialMessage = "Hello! Welcome to the chat.";

    // Create callback
    FBP_GFApiCallback Callback;
    Callback.BindDynamic(this, &UMyGameMode::OnChatCreated); // OnChatCreated is a UFUNCTION()

    // Create the chat
    ChatSystem->BP_CreateChat(Usernames, InitialMessage, Callback);
}

void UMyGameMode::OnChatCreated(FGFAPIResponse Response)
{
    if (Response.bSuccess)
    {
        UE_LOG(LogTemp, Display, TEXT("Chat created successfully"));

        // The chats saved by the last fetch or create
        UGameFuseChat* ChatSystem = GetGameInstance()->GetSubsystem<UGameFuseChat>();
        const TArray<FGFChat>& Chats = ChatSystem->GetCachedChats();

        if (Chats.Num() > 0)
        {
            UE_LOG(LogTemp, Display, TEXT("Chat ID: %d"), Chats.Last().Id);
        }
    }
    else
    {
        UE_LOG(LogTemp, Error, TEXT("Failed to create chat: %s"), *Response.ResponseStr);
    }
}

Sending Messages

AI message filtering

If the game has AI message filtering on (game Settings tab, off by default), GameFuse checks every message with the Typesafe Jev decision model before saving it. This includes the first message of a new chat. The default rules block swearing, crude or sexual talk, racism and slurs; the developer can rewrite them. A message that breaks the rules is not saved: the callback reports failure (HTTP 422) and the error text starts with the error code message_rejected. If the developer is out of AI credits and chose to block, the code is message_filter_no_credits. The check costs the developer about $0.00006 per message from their AI credits and adds about a second.

Once you have a chat, you can send messages to it:

void UMyGameMode::SendMessage(int32 ChatId, const FString& Message)
{
    UGameFuseChat* ChatSystem = GetGameInstance()->GetSubsystem<UGameFuseChat>();

    // Create typed callback
    FGFMessageCallback OnSendMessage;
    OnSendMessage.BindLambda([this](const FGFMessage& SentMessage) {
        // Use SentMessage data (ID, text, chatId, etc.)
    });

    // Send the message
    ChatSystem->SendMessage(ChatId, Message, OnSendMessage);
}

For Blueprint usage:

void UMyGameMode::SendMessageBP(int32 ChatId, const FString& Message)
{
    UGameFuseChat* ChatSystem = GetGameInstance()->GetSubsystem<UGameFuseChat>();

    // Create callback
    FBP_GFApiCallback Callback;
    Callback.BindDynamic(this, &UMyGameMode::OnMessageSent);

    // Send the message
    ChatSystem->BP_SendMessage(ChatId, Message, Callback);
}

void UMyGameMode::OnMessageSent(FGFAPIResponse Response)
{
    if (Response.bSuccess)
    {
        // The message was sent
    }
    else
    {
        // Response.ResponseStr holds the error text
    }
}

Marking Messages as Read

You can mark messages as read to keep track of which messages have been seen:

void UMyGameMode::MarkMessageAsRead(int32 MessageId)
{
    UGameFuseChat* ChatSystem = GetGameInstance()->GetSubsystem<UGameFuseChat>();

    // FGFSuccessCallback is a dynamic delegate: bind a UFUNCTION(), not a lambda
    FGFSuccessCallback OnMarkMessageAsRead;
    OnMarkMessageAsRead.BindDynamic(this, &UMyGameMode::OnMessageRead);

    // Mark the message as read
    ChatSystem->MarkMessageAsRead(MessageId, OnMarkMessageAsRead);
}

// Declared in the header as:  UFUNCTION() void OnMessageRead(bool bSuccess);
void UMyGameMode::OnMessageRead(bool bSuccess)
{
    // true when the message was marked as read
}

For Blueprint usage:

void UMyGameMode::MarkMessageAsReadBP(int32 MessageId)
{
    UGameFuseChat* ChatSystem = GetGameInstance()->GetSubsystem<UGameFuseChat>();

    // Create callback
    FBP_GFApiCallback Callback;
    Callback.BindDynamic(this, &UMyGameMode::OnMessageMarkedAsRead);

    // Mark the message as read
    ChatSystem->BP_MarkMessageAsRead(MessageId, Callback);
}

void UMyGameMode::OnMessageMarkedAsRead(FGFAPIResponse Response)
{
    if (Response.bSuccess)
    {
        // The message was marked as read
    }
    else
    {
        // Response.ResponseStr holds the error text
    }
}

Fetching Chats and Messages

You can fetch all chats for the current user:

void UMyGameMode::FetchAllChats()
{
    UGameFuseChat* ChatSystem = GetGameInstance()->GetSubsystem<UGameFuseChat>();

    // Create typed callback
    FGFChatListCallback OnFetchAllChats;
    OnFetchAllChats.BindLambda([this](const TArray<FGFChat>& Chats) {
        // Process array of chats for display
    });

    // Fetch all chats (page 1)
    ChatSystem->FetchAllChats(1, OnFetchAllChats);
}

For Blueprint usage:

void UMyGameMode::FetchAllChatsBP()
{
    UGameFuseChat* ChatSystem = GetGameInstance()->GetSubsystem<UGameFuseChat>();

    // Create callback
    FBP_GFApiCallback Callback;
    Callback.BindDynamic(this, &UMyGameMode::OnChatsReceived);

    // Fetch all chats (page 1)
    ChatSystem->BP_FetchAllChats(1, Callback);
}

void UMyGameMode::OnChatsReceived(FGFAPIResponse Response)
{
    if (Response.bSuccess)
    {
        // Read the chats from ChatSystem->GetCachedChats()
    }
    else
    {
        // Response.ResponseStr holds the error text
    }
}

You can also fetch messages for a specific chat:

void UMyGameMode::FetchMessages(int32 ChatId)
{
    UGameFuseChat* ChatSystem = GetGameInstance()->GetSubsystem<UGameFuseChat>();

    // Create typed callback
    FGFMessageListCallback OnFetchMessages;
    OnFetchMessages.BindLambda([this, ChatId](const TArray<FGFMessage>& Messages) {
        // Process array of messages for display
    });

    // Fetch messages (page 1)
    ChatSystem->FetchMessages(ChatId, 1, OnFetchMessages);
}

For Blueprint usage:

void UMyGameMode::FetchMessagesBP(int32 ChatId)
{
    UGameFuseChat* ChatSystem = GetGameInstance()->GetSubsystem<UGameFuseChat>();

    // Create callback
    FBP_GFApiCallback Callback;
    Callback.BindDynamic(this, &UMyGameMode::OnMessagesReceived);

    // Fetch messages (page 1)
    ChatSystem->BP_FetchMessages(ChatId, 1, Callback);
}

void UMyGameMode::OnMessagesReceived(FGFAPIResponse Response)
{
    if (Response.bSuccess)
    {
        // Read the messages from ChatSystem->GetChatMessages()
    }
    else
    {
        // Response.ResponseStr holds the error text
    }
}

After a fetch, the results are also kept on the subsystem. GetCachedChats() returns the last fetched chats and GetChatMessages() returns the last fetched messages. Both are Blueprint nodes too.

Clearing Chat Data

You can clear the cached chat data when it's no longer needed:

UGameFuseChat* ChatSystem = GetGameInstance()->GetSubsystem<UGameFuseChat>();
ChatSystem->ClearChatData();

Function Return Values

Chat Creation

HTTP status code Description
200 OK
400 Missing or invalid parameters
401 User not authenticated
500 Unknown server error

Message Operations

HTTP status code Description
200 OK
400 Missing or invalid parameters
401 User not authenticated or not a participant in the chat
404 Chat or message not found
500 Unknown server error

Fetching Data

HTTP status code Description
200 OK
401 User not authenticated
500 Unknown server error