> ## Documentation Index
> Fetch the complete documentation index at: https://docs.photon.codes/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Use Stable documentation by default. Honor an explicit Beta request or a URL under /docs/beta/. If the requested version conflicts with the installed CLI package or API origin, clarify the target before writing integration code.
> Pages under /docs/beta/ document Beta; other product pages document Stable. Keep the CLI package, commands, API origin, and credentials within the selected version. State the documentation version in your answer.
> For MCP search, always pass version: Stable or version: Beta. Unfiltered search mixes both versions. For filesystem reads, keep Beta queries under /beta/ and exclude /beta/ from Stable queries; discover paths before reading them.
> The public docs base is https://photon.codes/docs. Convert MCP page paths to public URLs under that base, preserving /beta/ when present. Read https://photon.codes/docs/skill.md for version selection and https://photon.codes/docs/llms.txt for the version indexes.

# MessageChain

> Published @photon-ai/imessage-kit type reference.

Message Processing Chain

Note: You must explicitly call execute() to perform operations

```ts theme={null}
await sdk.message(msg)
  .ifFromOthers()
  .matchText('hello')
  .replyText('Hi!')
  .execute()  // Must call execute()
```

## Constructor

```typescript theme={null}
MessageChain(message: Message, sender: MessageSender): MessageChain
```

### Parameters

**message** `Message` *required*

Message

**sender** `MessageSender` *required*

Sender

### Returns

`MessageChain`

## Methods

### do()

```typescript theme={null}
do(handler: (message: Message) => void | Promise<void>): this
```

Execute custom operation

#### Parameters

**handler** `(message: Message) =\> void | Promise\<void\>` *required*

**Type:** `(message: Message) => void | Promise<void>`

#### Returns

`this`

### execute()

```typescript theme={null}
execute(): Promise<void>
```

Execute all operations (explicit call)

This is the only method that actually performs operations

#### Returns

`Promise<void>`

### ifFromMe()

```typescript theme={null}
ifFromMe(): this
```

Only process my own messages

#### Returns

`this`

### ifFromOthers()

```typescript theme={null}
ifFromOthers(): this
```

Only process messages from others

#### Returns

`this`

### ifGroupChat()

```typescript theme={null}
ifGroupChat(): this
```

Only process group chat messages

#### Returns

`this`

### ifNotReaction()

```typescript theme={null}
ifNotReaction(): this
```

Only process non-reaction messages (skip tapbacks)

#### Returns

`this`

### ifReaction()

```typescript theme={null}
ifReaction(): this
```

Only process tapback reactions

#### Returns

`this`

### ifUnread()

```typescript theme={null}
ifUnread(): this
```

Only process unread messages

#### Returns

`this`

### matchText()

```typescript theme={null}
matchText(pattern: string | RegExp): this
```

Match text pattern

#### Parameters

**pattern** `string | RegExp` *required*

#### Returns

`this`

### replyImage()

```typescript theme={null}
replyImage(images: string | string[] | Mapper<Message, string | string[]>): this
```

Reply with image

Automatically routes to recipient or group based on message.chatId

#### Parameters

**images** `string | string[] | Mapper\<Message, string | string[]\>` *required*

**Type:** `string | string[] | Mapper<Message, string | string[]>`

#### Returns

`this`

### replyText()

```typescript theme={null}
replyText(text: string | Mapper<Message, string>): this
```

Reply with text

Automatically routes to recipient or group based on message.chatId

#### Parameters

**text** `string | Mapper\<Message, string\>` *required*

**Type:** `string | Mapper<Message, string>`

#### Returns

`this`

### when()

```typescript theme={null}
when(predicate: Predicate<Message>): this
```

Conditional check

#### Parameters

**predicate** `Predicate\<Message\>` *required*

**Type:** `Predicate<Message>`

#### Returns

`this`


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.