0

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:

messenger window

I expect the Arabic sentence to be aligned from right to left, and the others from left to right.

How can I do that?

soufiane yakoubi
  • 861
  • 11
  • 31
  • Maybe something like inserting a left-to-right mark in the appropriate position could help, or whatever else Unicode provides in regards to controlling script direction. But no guarantees Messenger will support it. For a quick fix, maybe you could just put the Arabic option last in this particular instance. – CBroe Aug 27 '21 at 06:26
  • I tried messing around with LTR and RTL Unicode marks, but nothing works, I also tried your suggestion by putting the Arabic sentence last without success. – soufiane yakoubi Aug 27 '21 at 17:55

0 Answers0