Using webhook will enable your device to respond on incoming message with dynamic response.
We will use express for easier usage.
Special note : any autoreply feature won't work if you are using webhook.
const express = require("express");
const app = express();
app.use(express.json());
async function sendFonnte(data) {
const url = "https://api.fonnte.com/send";
const customHeaders = {
"Content-Type": "application/json",
Authorization: TOKEN ,
};
const response = await fetch(url, {
method: "POST",
headers: customHeaders,
body: JSON.stringify(data),
});
console.log(await response.json());
}
app.post("/webhook", function (req, res) {
console.log(req.body);
if (req.body.message == "test") {
const data = {
target: req.body.sender,
message: "working great!",
};
sendFonnte(data);
} else {
const data = {
target: req.body.sender,
message: "this is default reply from fonnte",
};
sendFonnte(data);
}
res.end();
});
app.listen(3000, function (err) {
if (err) console.log(err);
console.log("Server listening on PORT", 3000);
});
Available parameter
- Device - Your device number (not connected device)
- Sender - Sender's whatsapp number
- Message - The message
- Text - Button text message
- Member - Sender from a group
- Name - The sender's name
- Location - Sender's send location latitude,longitude
- Url - The file url if sender an send attachment
- Filename - The filename of the attachment
- Extension - The extension of the attachment
Replying using attachment is only available on devices with a package of super, advanced or ultra.