yophone-bot-api
v0.0.3
Published
YoPhone Client for Node/Typescript
Maintainers
Readme
Get Started
For first, download the free application YoPhone and join!
YoPhone Client
A Node.js client for the YoPhone API.
Installation
npm install yophone-bot-apiUsage
import { Bot, message } from 'yophone-bot-api';
const bot = new Bot('YOUR_API_TOKEN');
// Handle commands Start
bot.start(async (ctx) => {
await ctx.reply('Hello! I am a YoPhone bot.');
});
// Handle commands Help
bot.help(async (ctx) => {
await ctx.reply('Hello! I am a YopPhone bot.');
});
// Handle commands
bot.command('start', async (ctx) => {
await ctx.reply('Hello! I am a YoPhone bot.');
});
// Handle regular messages (last update) "text" => "message"
bot.on('message', async (ctx, next) => {
await ctx.reply('I reply your message: ' + ctx.content);
next();
});
// Handle regular messages by filter ( BETA )
bot.on('message('text' | 'emoji'), async (ctx) => {
await ctx.reply('I reply your message: ' + ctx.content);
});
// Setting up a listener for bot messages
bot.hears('Hello' | /Hello/, (ctx) => {
// This handler will be triggered if the user sends the message "Hello"
ctx.reply('Hello! How are you?');
});
// Send photos
bot.command('photo', async (ctx) => {
await ctx.replyWithPhoto('/path/to/photo.jpg');
});
// Start the bot
bot.lounch();Update
Now you can use ctx.yoPhone.sendMessage(chatId, text) to send message by Chat Id.
bot.on('message', async (ctx, next) => {
const chatId = ctx.update.chatId;
await ctx.yoPhone.sendMessage(chatId, 'Your message!');
});
Features
- Command handling
- Message handling
- Photo sending
- Middleware support
- Long polling updates
Development
Install dependencies:
npm installRun tests:
npm testBuild the package:
npm run build
License
MIT
