I can send messages to a messenger user successfully using this typescript function:
import env from "env-var";
import superagent from "superagent";
import prefix from "superagent-prefix";
const PAGE_ACCESS_TOKEN = env.get("PAGE_ACCESS_TOKEN").required().asString();
const agent = superagent.agent()
.use(prefix("https://graph.facebook.com/v11.0"))
.query({access_token: PAGE_ACCESS_TOKEN})
.accept("application/json")
.type("application/json");
/**
* Sends a text message via the messenger platform.
* @param message The message text. Previews will not be shown for the URLs in this field.
* @param psid The page-scoped user ID (PSID) of the message recipient.
* @param messaging_type The messaging type of the message being sent.
*/
export async function sendTextMessage(
message: string,
psid: string,
messaging_type: MessagingType = "RESPONSE",
) {
const response = await agent
.post("/me/messages")
.send({
messaging_type: messaging_type,
recipient: {id: psid},
message: {text: message},
});
return response.body as SendAPIResponse;
}
And I can use it like so:
const psid = "<Page scoped id for the target user>";
const message = [
"- المرجو اختيار اللغة.",
"- Please choose a language.",
"- Veuillez choisir une langue.",
].join("\n");
void sendTextMessage(message, psid);
My problem is that when I send the above message, the text alignment is messed up:
I expect the Arabic sentence to be aligned from right to left, and the others from left to right.
How can I do that?