Usage examples

Example

Ncloudchat React example

All sources are open in GitHub. You can download GitHub sources and use them through https://www.ncloudchat.com.

Full simple code example

This is an example of connecting, creating a channel, and sending a subscription message to the created channel.


// Initialization 
CloudChat nc = CloudChat.GetInstance();
await nc.initialize([PROJECT_ID]);
nc.dispatcher.onMessageReceived += e =>
{
    Console.WriteLine("received a new message: ", e);
};
await nc.Connect(
    userId: 'guest@company',
    name: 'Guest',
    profile: 'https://image_url',
    customField: 'json',
);
// Create channel
var channel = await nc.createChannel(new CloudChatSDK.Channel
{
    name = "New Channel",
    type = "PUBLIC",    // PUBLIC or PRIVATE
    customField = "customField"
});
var channel = await nc.createChannel({type:'PUBLIC', name:'First Channel', customField:'customField'});
var channel_id = channel.createChannel.channel.id.ToString();
// Subscribe to channel
await nc.subscribe(channel_id);
// Send message
var response = await nc.sendMessage(
        channelId: channel_id, 
        type:"text", 
        content: message
    );

Last updated