# 사용예제

## 예제 <a href="#undefined" id="undefined"></a>

### Ncloudchat React 예제

깃헙에 전체 소스가 공개되어 있으며, [깃헙소스](https://github.com/nbase-io/CloudChat-JS-Demo) 는 다운로드 하실 수 있으며, [https://www.ncloudchat.com](https://www.ncloudchat.com/) 을 통해 이용해 보실 수 있습니다.

### 전체 샘플 코드 예제 <a href="#undefined" id="undefined"></a>

접속하고 채널을 생성하고 생성된 채널에 가입 메시지를 발송하는 예제입니다.

```csharp

// 초기화 
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',
);
// 채널 생성
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();
// 채널 구독
await nc.subscribe(channel_id);
// 메시지 발송
var response = await nc.sendMessage(
        channelId: channel_id, 
        type:"text", 
        content: message
    );
```
