Created
July 25, 2023 17:24
-
-
Save oleh-zaporozhets/8b8f7551bbf259703f8b5843154621af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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