On this page

Invite users to channels

Requires App Context

Enable App Context for your keyset in the Admin Portal.

Invite users to private or group conversations, creating their channel membership. Invitations trigger an invite event that you can listen to and notify invited users.

icon

Usage in Blueprints and C++


To send notifications on invitations, implement custom logic to:

Invite one user

Request a user to join a channel with Invite().

Method signature

Input

* required
ParameterDescription
User *
Type: UPubnubUser*
Default:
n/a
User that you want to invite to a 1:1 channel.

Output

TypeDescription
UPubnubMembership*
Returned (modified) object containing the membership data.

Sample code

Invite support-agent-15 to join the high-prio-incidents channel.

1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9UPubnubChannel* Channel = Chat->GetChannel("high-prio-incidents");
10
11// Define user ID
12FString UserID = "support_agent_15";
13
14// Get the user and save the reference
15UPubnubUser* User = Chat->GetUser(UserID);
show all 17 lines

Invite multiple users

Request multiple users to join a channel with InviteMultiple(). Maximum 100 users per call.

Method signature

Input

* required
ParameterDescription
Users *
Type: TArray<UPubnubUser*>
Default:
n/a
Array of users you want to invite to the group channel. You can invite up to 100 users in one call.

Output

TypeDescription
TArray<UPubnubMembership*>
Returned (modified) array of objects containing the membership data.

Sample code

Invite support-agent-15 and support-agent-16 to join the high-prio-incidents channel.

1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9UPubnubChannel* Channel = Chat->GetChannel("high-prio-incidents");
10
11// Define user IDs
12FString UserID1 = "support_agent_15";
13FString UserID2 = "support_agent_16";
14
15// Get the user and save the reference
show all 23 lines

Listen to invite events

Monitor invitation events with ListenForEvents() and send notifications to invited users.

Events documentation

See Chat events for details on invite events.

Method signature

icon

Handle the response

Output

This method doesn't return any value.

Sample code

Listen for invitations received on the support channel.

1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9FString ChannelID = "support";
10
11// Create a pubnub response delegate
12// you MUST implement your own callback function to handle the response
13FOnPubnubEventReceived ListenResponse;
14ListenResponse.BindDynamic(this, &AMyActor::OnListenResponseReceived);
15
show all 20 lines
Last updated on