# Messaging

### Send a plain Text Message

Sending a plain text message is really simple. Just call the `sendTextMessage()` function on the `Mitter.Messaging` instance and pass a channel ID and text payload.

```
                appDelegate.mitter.messaging.sendTextMessage(
                    forChannel: "rakfT-XPdJb-WsucS-Pxy4B",
                    "Hello from iOS!"
                ) { result in
                    switch result {
                    case .success:
                        print("Message sent!")
                    case .error:
                        print("Couldn't send message")
                    }
                } 
```

Here you can specify the channel ID that you got while creating a new channel in the previous step.

Run the project and it should send out a new message to the channel.

### Get messages in a channel

You can get messages sent to a particular channel by calling the `getMessagesInChannel()` and passing in the channel ID:

```
appDelegate.mitter.messaging.getMessagesInChannel("rakfT-XPdJb-WsucS-Pxy4B") {
            result in
            switch result {
            case .success(let messages):
                print("Messages: \(messages)")
            case .error:
                print("Couldn't fetch messages")
            }
        }
```

Run the project and you should be getting a list of messages printed to your console log.


---

# 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.mitter.io/sdks/ios/messaging.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.
