# Chatting Guide

Omnitalk SDK에서는 어떤 타입의 룸이든 참여하게 되면 sendMessage API를 이용하여 채팅 메시지를 주고 받을 수 있습니다. message를 룸 전체 사용자에게 보내는 'send' action과 특정 사용자에게만 전달하는 'whisper' action이 있습니다. 귓속말 기능은 상대의 session을 target 인수로 전달해야합니다.&#x20;

## Step 0. SDK 초기화 및 객체 생성

Developer's Guide의 [Pre-requisite](https://docs.omnitalk.io/flutter/developers-guide/pre-requisite#4.)에서 장치 설정 및 개발 공통 사항을 참고하시기 바랍니다.&#x20;

## Step 1. 세션 생성

Omnitalk SDK 초기화를 제외한 모든 API 기능은 유효한 세션의 존재를 전제로 하고 있습니다. 세션의 생성을 위해 createSession API를 호출합니다. 사용하고 싶은 번호나 문자열을 userId로 전달해 등록할 수 있으며 생략시엔 Omnitalk 서버에서 부여한 임의의 id를 리턴받을 수 있습니다.

```dart
await sdk.createSession();
```

## Step 2. 룸 참여

```dart
await sdk.createRoom();
await sdk.joinRoom();
```

## Step 3. 메시지 보내기

```dart
await sdk.sendMessage(action: MessageAction.send, message: msg); // 룸 전체 메시지 전송
await sdk.sendMessage(
   action : MessageAction.whisper,
   message : whispermsg,
   target : target,
   );  // 특정 상대에 귓속말 메시지 전송
```

## Step 4. 메시지 수신하기

룸의 다른 사용자가 보내는 메시지는 `MESSAGE_EVENT`를 수신하면 됩니다.&#x20;

```dart
sdk.on('event', (dynamic event) {
    switch(event['cmd']){
        case 'MESSAGE_EVENT':
            print(event['message']);
            print(event['user_id']);
            print(event['action'];
        }
    }
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.omnitalk.io/flutter/developers-guide/chatting-guide.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
