Update: I was able to get a Fax Sent message by passing a bufferValue to form.append(). Two things I need help with now please: First it says the fax was sent but queued (is there a reason for this?). Second, when I pass in binary data file I get the following Error
For binary data filename with extension should be specified, attachment
var bufferValue = Buffer.from(base64Data, "base64");
formData.append(
"attachment",
bufferValue,
require("fs").createReadStream("assets/SampleFAXOut.pdf")
);``
`
First, who says the fax was sent? Fax status is returned immediately after calling the API and normally it is in "Queued" stage. You can use the message id in the response to check the fax status later
async function checkFaxStatus(faxId){
try{
var resp = await platform.get('/restapi/v1.0/account/~/extension/~/message-store/' + faxId)
var jsonObj = await resp.json()
console.log(jsonObj)
}catch(e){
console.log(e.message)
}
}
Second, if you load the data to a buffer, why do you need to read the file again? Here is what you should attach the data buffer to the formData.
var bufferValue = Buffer.from(base64Data, "base64");
formData.append('attachment', bufferValue, 'thefilename.png');
Thank you for responding. I got that from the response object. Reading the file again was my bad. Here's the new code and still saying Fax is queued.
const send_fax = async (formData) => {
const body = {
to: [{ phoneNumber: RECIPIENT }],
faxResolution: "High",
coverPageText: "This is a demo Fax page",
};
formData.append("json", Buffer.from(JSON.stringify(body)), {
filename: "SampleFAXOut.pdf",
contentType: "application/json",
});
const buf = require("fs")
.readFileSync("assets/SampleFAXOut.pdf")
.toString("utf8");
formData.append("attachment", buf, "SampleFAXOut.pdf");
try {
const resp = await platform.post(
"/restapi/v1.0/account/~/extension/~/fax",
formData
);
const jsonObj = await resp.json();
console.log("FAX sent. Message status: ", JSON.stringify(jsonObj, null, 2));
} catch (e) {
console.log("Error Sending Fax:", e.message);
}
};
Reponse:
{
"uri": "https://platform.devtest.ringcentral.com/restapi/v1.0/account/<removed>/extension/<removed>/message-store/12017291004",
"id": 12017291004,
"to": [
{
"recipientId": "7882892004",
"phoneNumber": "+18338251687",
"messageStatus": "Queued"
}
],
"type": "Fax",
"creationTime": "2022-11-11T16:46:11.000Z",
"readStatus": "Unread",
"priority": "Normal",
"attachments": [
{
"id": 12017291004,
"uri": "https://media.devtest.ringcentral.com/restapi/v1.0/account/754779005/extension/754779005/message-store/12017291004/content/12017291004",
"type": "RenderedDocument",
"contentType": "application/pdf"
}
],
"direction": "Outbound",
"availability": "Alive",
"messageStatus": "Queued",
"faxResolution": "High",
"faxPageCount": 0,
"lastModifiedTime": "2022-11-11T16:46:11.156Z",
"coverIndex": 7,
"coverPageText": "This is a demo Fax page from Node JS"
}
First of all, it would take some time to send a fax. So you need to read the status after some time to check or you can subscribe for the message-store event notification to get notified when the fax status changed.
Note. There is a known issue in sandbox (not sure if it's fixed or not) that the actual attachments will not be sent in sandbox. But the cover page should be sent and the fax status should be updated as Sent or other status accordingly.
If after a few mins you still see the Fax status in queued and/or you received the fax at the destination but the fax status still remain in "Queued", then that is a bug on sandbox. Please report it.
Thank you. Will update or report bug based on new findings. Have a great weekend!