UrbanBotTelegram
Urban bot part which is responsible to launch telegram bot.
Install
npm i @urban-bot/telegram --save
yarn add @urban-bot/telegram
Usage
import { render, Root, Text } from '@urban-bot/core';
import { UrbanBotTelegram } from '@urban-bot/telegram';
const urbanBotTelegram = new UrbanBotTelegram({
token: 'telegramToken',
});
render(
<Root bot={urbanBotTelegram}>
<Text>Hello, Telegram!</Text>
</Root>,
);
Options
token
A telegram token. You can get it from @BotFather.
required
string
const urbanBotTelegram = new UrbanBotTelegram({
token: '323452248:YYHG68zEKHl2NWQ5c_y1l9blh5wXmn385u4',
});
isPolling
Enabling long polling.
optional
false
default boolean
const urbanBotTelegram = new UrbanBotTelegram({
isPolling: true,
});
Bot Instance
You could get bot instance by useBotContext
.
function SomeComponent() {
const { bot } = useBotContext();
// ...
}
type
Bot type.
required
'TELEGRAM'
client
A client which you can use for call any Telegram API.
required
function SomeComponent() {
const { bot } = useBotContext();
useText(({ text, chat, from }) => {
if (text.includes('Fu**')) {
bot.client.kickChatMember(chat.id, from.id);
}
});
// ...
}