Chat
Overview
AccelByte Cloud's Chat service 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:
- 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.
- 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.
- 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.
- Global Chat allows users to broadcast messages to all users within the game. By default, the user can join a global channel and start broadcasting messages to other users in the game.
Permissions
Permissions are used to grant access to specific resources within our services. Make sure your account has the following permissions before you attempt to manage chat in the Admin Portal.
Usage | Resource | Action |
---|---|---|
Load Personal Chat History | NAMESPACE:{namespace}:USER:{userId}:CHAT | Read |
Get Chat History | NAMESPACE:{namespace}:USER:{userId}:CHAT | Read |
Load Personal Chat History based on Friend's User ID | Required valid user authorization | Read |
Permissions work slightly differently depending on whether they are assigned to IAM Clients or Roles assigned to users. For more information, read the Authentication and Authorization documentation.
Implement Chat using the Client SDKs
Chat features are handled by the Cloud 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.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetPrivateMessageResponseDelegate(AccelByte::Api::Lobby::FPersonalChatResponse::CreateLambda([](const FAccelByteModelsPersonalMessageResponse& Result)
{
if (Result.Code == "0")
{
// Do something if SendPrivateMessage has been successful
}
else
{
// Do something if SendPrivateMessage has an error
}
}));
FString UserId = FString("SomeTargetUserId");
FString Message = FString("Your Message");
FRegistry::Lobby.SendPrivateMessage(UserId, Message);
string userId = "SomeTargetUserId";
string message = "Your Message";
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().SendPersonalChat(userId, message, result =>
{
if (result.IsError)
{
// Do something if SendPersonalChat has an error
Debug.Log($"Error SendPersonalChat, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if SendPersonalChat has been successful
}
});
Receive a Personal Chat
Personal chats can be received by registering to the personal chat event.
- Unreal Engine
- Unity
FRegistry::Lobby.SetPrivateMessageNotifDelegate(AccelByte::Api::Lobby::FPersonalChatNotif::CreateLambda([](const FAccelByteModelsPersonalMessageNotice& Result)
{
// Do something if PrivateMessageNotifDelegate has been retrieved successfully
}));
AccelBytePlugin.GetLobby().PersonalChatReceived += result =>
{
if (result.IsError)
{
// Do something if PersonalChatReceived has an error
Debug.Log($"Error PersonalChatReceived, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if PersonalChatReceieved has been successful
}
};
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. The Party ID will be obtained automatically after the player has already joined the party.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetPartyMessageResponseDelegate(AccelByte::Api::Lobby::FPartyChatResponse::CreateLambda([](const FAccelByteModelsPartyMessageResponse& Result)
{
if (Result.Code == "0")
{
// Do something if PartyMessageResponseDelegate has been retrieved successfully
}
else
{
// Do something if PartyMessageResponseDelegate has an error
}
}));
FString Message = FString("Your Message");
FRegistry::Lobby.SendPartyMessage(Message);
string message = "Your Message";
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().SendPartyChat(message, result =>
{
if (result.IsError)
{
// Do something if SendPartyChat has an error
Debug.Log($"Error SendPartyChat, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if SendPartyChat has been successful
}
});
Receive a Party Chat
A party chat can be received by registering to a party chat event.
- Unreal Engine
- Unity
FRegistry::Lobby.SetPartyChatNotifDelegate(AccelByte::Api::Lobby::FPartyChatNotif::CreateLambda([](const FAccelByteModelsPartyMessageNotice& Result)
{
// Do something if PartyChatMessageNotifDelegate has been retrieved successfully
}));
AccelBytePlugin.GetLobby().PartyChatReceived += result =>
{
if (result.IsError)
{
// Do something if PartyChatReceived has an error
Debug.Log($"Error PartyChatReceived, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if PartyChatReceived has been successful
}
};
Global Chat
Join a Default Channel
Players can join a default channel to chat with all other players currently logged into the game.
- Unreal Engine
- Unity
FRegistry::Lobby.SetJoinChannelChatResponseDelegate(AccelByte::Api::Lobby::FJoinDefaultChannelChatResponse::CreateLambda([](const FAccelByteModelsJoinDefaultChannelResponse& Result)
{
// Do something if JoinChannelChat has been successful
}));
FRegistry::Lobby.SendJoinDefaultChannelChatRequest();
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().JoinDefaultChatChannel(result =>
{
if (result.IsError)
{
// Do something if JoinDefaultChatChannel has an error
Debug.Log($"Error JoinDefaultChatChannel, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if JoinDefaultChatChannel has been successful
}
});
Send a Global Chat
Sending a message through a global default channel to get interact with some message for all players that have already joined the global channel.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetChannelMessageResponseDelegate(AccelByte::Api::Lobby::FChannelChatResponse::CreateLambda([](const FAccelByteModelsChannelMessageResponse& Result)
{
if (Result.Code == "0")
{
// Do something if ChannelMessageResponseDelegate has been successful
}
else
{
// Do something if ChannelMessageResponseDelegate has an error
}
}));
FString Message = FString("Your Message");
FRegistry::Lobby.SendChannelMessage(Message);
string message = "Your Message";
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().SendChannelChat(message, result =>
{
if (result.IsError)
{
// Do something if SendChannelChat has an error
Debug.Log($"Error SendChannelChat, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if SendChannelChat has been successful
}
});
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:
- Unreal Engine
- Unity
FRegistry::Lobby.SetChannelMessageNotifDelegate(AccelByte::Api::Lobby::FChannelChatNotif::CreateLambda([](const FAccelByteModelsChannelMessageNotice& Result)
{
// Do something if ChannelMessageNotifDelegate has been retrieved successfully
}));
AccelBytePlugin.GetLobby().ChannelChatReceived += result =>
{
if (result.IsError)
{
// Do something if ChannelChatReceived has an error
Debug.Log($"Error ChannelChatReceived, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if ChannelChatReceived has been successful
}
};
Related Concepts
- For the technical details about Chat, take a look at our Cloud API References.