Chat

Overview

Chat is a service that allows players to send and receive messages to their friends or party members in real-time. This service includes notifications to inform users of messages being sent or received. The Chat service is divided into three basic features:

  1. Chat: Send Personal Chat allows players to message their friends. The sender will receive a notification when their message has been sent, and the recipient will receive a notification when they have a new message.
  2. Chat: Send Party Chat allows users to send a message to all of the players in their party. The party members will be notified when they have a new message from the sender.
  3. Load Personal Chat History involves retrieving a player’s chat history with another player. This action can be performed by sending an HTTP Request only if the player has permission to perform this action, i.e. the player hasn’t been blocked.

Tutorials

Chat features are handled by the Lobby service. You must connect to the Lobby service before you can enable chat.

Personal Chat

Players can communicate with other players using personal chat.

Send a Personal Chat

A player can send a personal message to any other player, if they know their User ID.

AccelByte::FRegistry::Lobby.SetPrivateMessageResponseDelegate(
AccelByte::Api::Lobby::FPersonalChatResponse::CreateLambda([](const FAccelByteModelsPersonalMessageResponse& Result)
{
if (Result.Code == "0")
{
UE_LOG(LogTemp, Log, TEXT("Message sent successfully."));
}
else
{
UE_LOG(LogTemp, Log, TEXT("Failed to send a private message! Code: %s"), *Result.Code);
}
}));
AccelByte::FRegistry::Lobby.SetPrivateMessageResponseDelegate(
AccelByte::Api::Lobby::FPersonalChatResponse::CreateLambda([](const FAccelByteModelsPersonalMessageResponse& Result)
{
if (Result.Code == "0")
{
UE_LOG(LogTemp, Log, TEXT("Message sent successfully."));
}
else
{
UE_LOG(LogTemp, Log, TEXT("Failed to send a private message! Code: %s"), *Result.Code);
}
}));
FString UserId = "YourFriendUserId";
AccelByte::FRegistry::Lobby.SendPrivateMessage(UserId, TEXT("Hello, How are you?"));

Receive a Personal Chat

Personal chats can be received by registering to the personal chat event.

AccelByte::FRegistry::Lobby.SetPrivateMessageNotifDelegate(
AccelByte::Api::Lobby::FPersonalChatNotif::CreateLambda([](const FAccelByteModelsPersonalMessageNotice& Result)
{
UE_LOG(LogTemp, Log, TEXT("%s send a private message to you (%s)!"), *Result.From, *Result.To);
UE_LOG(LogTemp, Log, TEXT("Message:\n%s"), *Result.Payload);
}));

Party Chat

When a party has been formed, its members can use the chat feature to communicate with each other. Every message sent will be received by all of the party members.

Send a Party Chat

The Lobby service will automatically direct a player’s messages to their own party, so the player doesn’t need to know their Party ID.

AccelByte::FRegistry::Lobby.SetPartyMessageResponseDelegate(
AccelByte::Api::Lobby::FPartyChatResponse::CreateLambda([](const FAccelByteModelsPartyMessageResponse& Result)
{
if (Result.Code == "0")
{
UE_LOG(LogTemp, Log, TEXT("Successfully send a party message!"));
}
else
{
UE_LOG(LogTemp, Log, TEXT("Failed to send a party message! Code: %s"), *Result.Code);
}
}));
AccelByte::FRegistry::Lobby.SendPartyMessage(TEXT("Hello, my party."));

Receive a Party Chat

A party chat can be received by registering to a party chat event.

AccelByte::FRegistry::Lobby.SetPartyChatNotifDelegate(
AccelByte::Api::Lobby::FPartyChatNotif::CreateLambda([](const FAccelByteModelsPartyMessageNotice& Result)
{
UE_LOG(LogTemp, Log, TEXT("%s send a party message to this party (%s)!"), *Result.From, *Result.To);
UE_LOG(LogTemp, Log, TEXT("Message:\n%s"), *Result.Payload);
}))

Global Chat

Join a Default Channel

Players can join a default channel to chat with all other players currently logged into the game.

AccelByte::FRegistry::Lobby.SetChannelMessageResponseDelegate(
AccelByte::Api::Lobby::FChannelChatResponse::CreateLambda([](const FAccelByteModelsChannelMessageResponse& Result)
{
if (Result.Code == "0")
{
UE_LOG(LogTemp, Log, TEXT("Successfully send a channel message!"));
}
else
{
UE_LOG(LogTemp, Log, TEXT("Failed to send a channel message! Code: %s"), *Result.Code);
}
}));
AccelByte::FRegistry::Lobby.SetJoinChannelChatResponseDelegate(THandler<FAccelByteModelsJoinDefaultChannelResponse>::CreateLambda([](const FAccelByteModelsJoinDefaultChannelResponse& result)
{
if (Result.Code == "0")
{
UE_LOG(LogTemp, Log, TEXT("Successfully join default channel message!"));
}
else
{
UE_LOG(LogTemp, Log, TEXT("Failed to join default channel message! Code: %s"), *Result.Code);
}
}));
AccelByte::FRegistry::Lobby.SendJoinDefaultChannelChatRequest();
AccelByte::FRegistry::Lobby.SendChannelMessage(TEXT("Hi! How are you people?"));

Receive a Global Chat

Receiving a message from a global channel can be done by registering to a channel chat event using the following code:

AccelByte::FRegistry::Lobby.SetChannelMessageNotifDelegate(THandler<FAccelByteModelsChannelMessageNotice>::CreateLambda([](const FAccelByteModelsChannelMessageNotice& result)
{
UE_LOG(LogTemp, Log, TEXT("%s send a channel message!"), *Result.From);
UE_LOG(LogTemp, Log, TEXT("Message:\n%s"), *Result.Payload);
}));

Related Concepts

  • For the technical details about Chat, take a look at our API References.