Skip to main content

Text Message

Hướng dẫn tạo text message và system message với SmartMessage builder.

Text Message

Text message là loại message cơ bản nhất, chỉ chứa text thuần túy.

Cú pháp

SmartMessage.text(content: string): SmartMessage

Ví dụ cơ bản

import { Command, AutoContext, SmartMessage } from '@n0xgg04/nezon';
import type { Nezon } from '@n0xgg04/nezon';

@Command('hello')
async onHello(@AutoContext() [managedMessage]: Nezon.AutoContext) {
await managedMessage.reply(SmartMessage.text('Hello, World!'));
}

Type

SmartMessage.text('Hello')
// Trả về: SmartMessage instance
// Có thể truyền vào: message.reply(), message.update()

Tương đương với Mezon SDK

// Với Nezon
await message.reply(SmartMessage.text('Hello'));

// Với Mezon SDK (thủ công)
await message.reply({ t: 'Hello' });

System Message

System message sử dụng markdown triple (EMarkdownType.PRE) để hiển thị nội dung trong khung đặc biệt, thường dùng cho thông báo hệ thống.

System Message Example

Cú pháp

SmartMessage.system(content: string): SmartMessage

Ví dụ

import { Command, AutoContext, SmartMessage } from '@n0xgg04/nezon';
import type { Nezon } from '@n0xgg04/nezon';

@Command('announce')
async onAnnounce(@AutoContext() [managedMessage]: Nezon.AutoContext) {
await managedMessage.reply(
SmartMessage.system('⚠️ Thông báo quan trọng!\n\nBot sẽ bảo trì vào 2h sáng.')
);
}

Type

SmartMessage.system('Content')
// Trả về: SmartMessage instance
// Nội dung sẽ được wrap trong markdown triple

Tương đương với Mezon SDK

// Với Nezon
await message.reply(SmartMessage.system('Content'));


## Kết hợp với các tính năng khác

### Text message với buttons

```ts
import { Command, AutoContext, SmartMessage, ButtonBuilder, ButtonStyle } from '@n0xgg04/nezon';
import type { Nezon } from '@n0xgg04/nezon';

@Command('menu')
async onMenu(@AutoContext() [managedMessage]: Nezon.AutoContext) {
await managedMessage.reply(
SmartMessage.text('Chọn một tùy chọn:')
.addButton(
new ButtonBuilder()
.setLabel('Option 1')
.setStyle(ButtonStyle.Primary)
)
.addButton(
new ButtonBuilder()
.setLabel('Option 2')
.setStyle(ButtonStyle.Secondary)
)
);
}

System message với embed

import { Command, AutoContext, SmartMessage, EmbedBuilder } from '@n0xgg04/nezon';
import type { Nezon } from '@n0xgg04/nezon';

@Command('notice')
async onNotice(@AutoContext() [managedMessage]: Nezon.AutoContext) {
await managedMessage.reply(
SmartMessage.system('Thông báo hệ thống')
.addEmbed(
new EmbedBuilder()
.setTitle('Cập nhật mới')
.setDescription('Phiên bản 0.0.7 đã được phát hành!')
.setColor('#00ff00')
)
);
}

So sánh Text vs System

Tính năngText MessageSystem Message
MarkdownKhôngTriple markdown
Hiển thịText thườngKhung đặc biệt
Use caseTin nhắn thông thườngThông báo hệ thống
Cú phápSmartMessage.text()SmartMessage.system()

Best Practices

  1. Sử dụng Text cho tin nhắn thông thường

    SmartMessage.text('Hello!')
  2. Sử dụng System cho thông báo quan trọng

    SmartMessage.system('⚠️ Cảnh báo!')
  3. Kết hợp với buttons/embeds khi cần

    SmartMessage.text('Menu')
    .addButton(...)
    .addEmbed(...)

API Reference

SmartMessage.text()

Signature:

static text(content: string): SmartMessage

Parameters:

  • content: string - Nội dung text message

Returns:

  • SmartMessage - Instance có thể chain với .addButton(), .addEmbed(), etc.

SmartMessage.system()

Signature:

static system(content: string): SmartMessage

Parameters:

  • content: string - Nội dung system message

Returns:

  • SmartMessage - Instance có thể chain với .addButton(), .addEmbed(), etc.

Reaction Methods

ManagedMessage cung cấp các methods để tương tác với reactions trên message:

react(emoji: string, emojiId?: string, actionDelete?: boolean)

React hoặc remove reaction trên message.

await managedMessage.react('👍');
await managedMessage.react('👍', undefined, true); // Remove reaction

addReaction(emoji: string, emojiId?: string)

Thêm reaction (convenience method).

await managedMessage.addReaction('👍');
await managedMessage.addReaction('❤️');

removeReaction(emoji: string, emojiId?: string)

Xóa reaction (convenience method).

await managedMessage.removeReaction('👍');

Ví dụ:

@Command('react')
async onReact(@AutoContext() [message]: Nezon.AutoContext) {
await message.addReaction('👍');
await message.reply(SmartMessage.text('Đã thêm reaction!'));
}

Lưu ý:

  • Reaction methods hoạt động với cả message của user và bot
  • Nếu message entity không tìm thấy, sẽ throw error
  • Có thể dùng với getManagedMessage() từ NezonUtilsService để react vào message khác

Xem thêm