Skip to content

Instantly share code, notes, and snippets.

@ilamanov
Last active January 29, 2022 08:20
Show Gist options
  • Save ilamanov/9137b0594c9e6d953f8ff719caf2422d to your computer and use it in GitHub Desktop.
Save ilamanov/9137b0594c9e6d953f8ff719caf2422d to your computer and use it in GitHub Desktop.
Telegram BOT contant reply
const TELEGRAM_TOKEN = "..."
export default async (req, res) => {
const chat_id = req.body.message.chat.id;
await respond(chat_id, "Buy Milk")
res.status(200).send({});
}
async function respond(chat_id, responseText) {
await fetch(
`https://api.telegram.org/bot${TELEGRAM_TOKEN}/sendMessage`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
chat_id: chat_id,
text: responseText,
})
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment