Skip to content

Instantly share code, notes, and snippets.

@oleh-zaporozhets
Created July 25, 2023 17:24
Show Gist options
  • Save oleh-zaporozhets/8b8f7551bbf259703f8b5843154621af to your computer and use it in GitHub Desktop.
Save oleh-zaporozhets/8b8f7551bbf259703f8b5843154621af to your computer and use it in GitHub Desktop.
import axios, { AxiosInstance } from 'axios';
interface ITelegramBot {
sendMessage(chatId: string, message: string): Promise<void>;
}
class TelegramBot implements ITelegramBot {
private axiosInstance: AxiosInstance;
public constructor(botToken: string) {
this.axiosInstance = axios.create({
baseURL: `https://api.telegram.org/bot${botToken}`,
});
}
public sendMessage = (chatId: string, message: string): Promise<void> => {
return this.axiosInstance.get(
`/sendMessage?chat_id=${chatId}&text=${message}`,
);
};
}
export { ITelegramBot, TelegramBot };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment