Facebook Messenger Chatbot: Using NodeJS Fetch function and New Line
Here is the code:
- To display new blank line in FB messenger bot, use \r\n as above.
Hope it helps.
const PAGE_ACCESS_TOKEN = "your_long_FB_page_access_token" let my_return_answer = 'my answer<br>another answer' // Construct the message body let request_body = { "recipient": { "id": senderID // This value coming from webhook_event.sender.id }, "message": { "text": my_return_answer.replace(/<br>/g, "\r\n") } } fetch("https://graph.facebook.com/v2.6/me/messages/?access_token=" + PAGE_ACCESS_TOKEN, { method: "POST", body: JSON.stringify(request_body), headers: { 'Content-Type': 'application/json', }, }).then((res) => res.json()) .then((fb_json) => { console.log({fb_json}) })- If you are using NodeJS fetch function, please use the above code as reference
- To display new blank line in FB messenger bot, use \r\n as above.
Hope it helps.
Comments