Hello,
First of all, don’t be hesitate to ask a question if confuse about my question.
So, i was making Tele BOT using REST API. But, when i trigger my REST API using postman, the result is in below :
TypeError: fetch failed
at node:internal/deps/undici/undici:13185:13
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async exports.sendMessage (/root/LESS24H-Digiflazz/controller/tele/sendMessageController.js:25:21) {
[cause]: AggregateError [ETIMEDOUT]:
at internalConnectMultiple (node:net:1122:18)
at internalConnectMultiple (node:net:1190:5)
at Timeout.internalConnectMultipleTimeout (node:net:1716:5)
at listOnTimeout (node:internal/timers:596:11)
at process.processTimers (node:internal/timers:529:7) {
code: 'ETIMEDOUT',
[errors]: [ [Error], [Error] ]
}
}
This is my code:
const dotenv = require("dotenv");
dotenv.config();
exports.sendMessage = async (req, res) => {
const { message } = req.body;
if (!req.body || Object.keys(req.body).length === 0) {
return res.status(400).json({
status: 400,
message: "Bad request",
});
}
try {
const teleUrl = process.env.TELE_API_URL;
const teleToken = process.env.TELE_TOKEN;
const teleChannelId = process.env.TELE_CHANNEL_ID;
const request = await fetch(
`${teleUrl}/bot${teleToken}/sendMessage`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(
{
chat_id: teleChannelId,
text: message,
},
{ family: 4 }
),
}
);
res.status(200).json({ status: 200, message: "Success", data: request });
} catch (error) {
console.error(error);
res.status(500).json({ status: 500, message: "Internal server error" });
}
};
All the request like Message, Token, Channel ID and ect is nothing wrong because working on local. And also i already setting the VPC Network, Firewall Rule with this configuration :
- Direction: Egress
- Action on Match: Allow
- Destination Filters: 0.0.0.0/0
- Protocols and Ports: 443/tcp
I already do this method, but still came with same result. I think something missing, can you tell me?
Thank you