How to send message to telegram bot api

My worker is returning {ok: false, error_code: 400, description: 'Bad Request: message text is empty'} when I make an API call to Telegram. However, I don't see any problems with my fetch request within my worker. What am I missing in my fetch function?
const sendMessage = async (message) => {

const token = '--'
const data = await fetch(`https://api.telegram.org/bot${token}/sendMessage`, {
method: "POST",
body: JSON.stringify({
chat_id: "---",
text: message
})
})

return await data.json()
}
const sendMessage = async (message) => {

const token = '--'
const data = await fetch(`https://api.telegram.org/bot${token}/sendMessage`, {
method: "POST",
body: JSON.stringify({
chat_id: "---",
text: message
})
})

return await data.json()
}
2 Replies
kian
kian14mo ago
Try adding a Content-Type: application/json request header
Ricardo Viteri
Ricardo Viteri14mo ago
life saver man the little things, always thanks!