Created
January 29, 2024 09:23
-
-
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
This file contains 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 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