پرش به مطلب اصلی

sendMessage

ارسال پیام با استفاده از ربات به یک کاربر، گروه یا کانال.

ورودی‌ها

نامنوعتوضیح
chat_idstringآیدی چتی که پیام باید به آن ارسال شود.
textstringمتن پیام
chat_keypadKeypad (اختیاری)کیبورد معمولی (Reply Keyboard) برای پیام.
inline_keypadInlineKeypad (اختیاری)کیبورد اینلاین همراه پیام.
disable_notificationboolean (پیش‌فرض: false)اگر true باشد، پیام بدون نوتیفیکیشن ارسال می‌شود.
reply_to_message_idstring (اختیاری)در صورت تعیین، پیام به این پیام پاسخ داده می‌شود.
chat_keypad_typeChatKeypadTypeEnum (اختیاری)نوع کیبورد برای ساخت یا تنظیم کیبورد چت.

خروجی

فیلدنوعتوضیح
message_idstringایدی پیام

مثال‌ها

1. ارسال پیام ساده متنی

const { Bot } = require("rubjs");

const bot = new Bot("YOUR_TOKEN");

bot.command("/start", async (ctx) => {
await bot.sendMessage(ctx.chat_id, "ربات استارت شد.");
});

bot.run();

2. ارسال پیام با کیبورد Reply (chat_keypad)

const { Bot } = require("rubjs");

const bot = new Bot("YOUR_TOKEN");

bot.command("/start", async (ctx) => {
await bot.sendMessage(ctx.chat_id, "ربات استارت شد.", {
rows: [
{
buttons: [
{ button_text: "درباره", id: "100", type: "Simple" },
{ button_text: "اطلاعات", id: "101", type: "Simple" },
],
},
],
on_time_keyboard: false,
resize_keyboard: true,
});
});

bot.run();

3. ارسال پیام با کیبورد اینلاین (inline_keypad)

const { Bot } = require("rubjs");

const bot = new Bot("YOUR_TOKEN");

bot.command("/start", async (ctx) => {
await bot.sendMessage(ctx.chat_id, "ربات استارت شد.", undefined, {
rows: [
{
buttons: [
{ button_text: "درباره", id: "100", type: "Simple" },
{ button_text: "اطلاعات", id: "101", type: "Simple" },
],
},
],
});
});

bot.run();

4. ارسال پیام بدون نوتیفیکیشن

const { Bot } = require("rubjs");

const bot = new Bot("YOUR_TOKEN");

bot.command("/start", async (ctx) => {
await bot.sendMessage(
ctx.chat_id,
"ربات استارت شد.",
undefined,
undefined,
false
);
});

bot.run();

5. ارسال پیام در پاسخ به یک پیام دیگر

const { Bot } = require('rubjs');

const bot = new Bot('YOUR_TOKEN');

bot.command('/start', async (ctx) => {
await bot.sendMessage(
ctx.chat_id,
'ربات استارت شد.',
undefined,
undefined,
true,
ctx.new_message.message_id,
);
});

bot.run();