urban-bot / urban-bot

🤖 The universal chatbot library based on React. Write once, launch Telegram, Discord, Facebook, ... every messenger with chatbots
https://urban-bot.now.sh
MIT License
562 stars 30 forks source link

SENDING MESSAGE TO A CHANNEL #310

Open aledrstudio opened 11 months ago

aledrstudio commented 11 months ago

Hii, how can I send a message to a channel when a user click a button?

aledrstudio commented 11 months ago
` function sendTextToChannel() {
        bot.sendMessage({
            chat_id: '@sviluppo1234',
            text: 'Questo è un messaggio di esempio dal mio bot React.',
        });
    }`
This is my code, but it doesn't work, 'bot' is the instance of the telegram Bot created here:
    `import { UrbanBotTelegram } from '@urban-bot/telegram';
import { render, Root } from '@urban-bot/core';
import dotenv from 'dotenv';
import { App } from '../App';
import PreHome from '../page/PreHome';

dotenv.config();

const { TELEGRAM_TOKEN, PORT } = process.env;

const isDevelopment = process.env.NODE_ENV === 'development';

if (!TELEGRAM_TOKEN) {
    throw new Error('Provide TELEGRAM_TOKEN to .env https://core.telegram.org/bots#6-botfather');
}

const urbanBotTelegram = new UrbanBotTelegram({
    token: TELEGRAM_TOKEN,
    isPolling: true,
});

render(
    <Root bot={urbanBotTelegram} port={PORT ? Number(PORT) : undefined}>
        <PreHome bot={urbanBotTelegram}></PreHome>
    </Root>,
    () => console.log('telegram bot has started'),
);
`
sergei-zheludkov commented 8 months ago
        chat_id: '@sviluppo1234',

because this isn't chat_id. You tried to pass nickname into the property chat_id