Skip to content

Instantly share code, notes, and snippets.

@mcpeblocker
Created January 29, 2024 09:23
Show Gist options
  • Save mcpeblocker/7d0908fcea2a0a49ce5cbc971c27d6ed to your computer and use it in GitHub Desktop.
Save mcpeblocker/7d0908fcea2a0a49ce5cbc971c27d6ed to your computer and use it in GitHub Desktop.
A script to use sendMessage method of Telegram Bot API by sending HTTP Request via axios
import axios from 'axios';
export const sendMessage = async (
botToken: string,
chatId: number,
text: string
): Promise<boolean> => {
try {
const response = await axios.post(`https://api.telegram.org/bot${botToken}/sendMessage`, {
chat_id: chatId,
text: text
});
if (response.data?.ok === true) {
return true;
} else {
false
}
} catch(error) {
return false;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment