Posts tagged with node.js

I Am trying to upload Reels from a business Instagram account for that i already have access token and long lived token.The problem is that whenever i try to publish a reel it gives me "The video file you selected is in a format that we don't support." error code:352 and error_subcode:2207026.I have also converted that video but its saying the same.But I am able to upload a video of "640x480" but not any other resolution like 720x1280 etc. The url of video is aws

I have tried converting video using ffmpeg but it gives me aspect ratio error on 720x1280 whether its 9:16 or 16:9 when i try to upload video of like 1080x1920 it gives me streams error i have also added validation in my uploadReel function and funtion return true but still i am getting video format not supported error

import { Request, Response } from 'express'; import axios from 'axios'; import asyncHandler from '../../../middlewares/asyncHandler'; import ffmpeg from 'fluent-ffmpeg'; import ffmpegInstaller from '@ffmpeg-installer/ffmpeg'; ffmpeg.setFfmpegPath(ffmpegInstaller.path); export const uploadReel = asyncHandler(async (req: Request, res: Response) => {   const { longLivedToken, videoUrl }: any = req.body;   if (!longLivedToken || !videoUrl) {     return res.status(400).json({ error: 'Invalid data' });   }   console.log('Checking video format for:', videoUrl);   // Check if the video has supported codecs (H.264 for video and AAC for audio)   ffmpeg(videoUrl).ffprobe((err, metadata) => {     if (err) {       console.error('Error reading video metadata:', err.message);       return res.status(400).json({ error: 'Unable to check video metadata or invalid file.' });     }     console.log('Video metadata:', JSON.stringify(metadata, null, 2));     const hasValidCodec = metadata.streams.some(       (stream: any) => stream.codec_name === 'h264' && stream.codec_type === 'video'     ) && metadata.streams.some(       (stream: any) => stream.codec_name === 'aac' && stream.codec_type === 'audio'     );     if (!hasValidCodec) {       console.error('Unsupported file format. Expected H.264 video codec and AAC audio codec.');       return res.status(400).json({         error: 'Unsupported file format. Ensure the video is in MP4 format with H.264 video codec and AAC audio codec.',       });     }     console.log('Video format is supported. Proceeding with upload.');     // If format is supported, proceed to upload the video     axios.post(       `https://graph.instagram.com/v20.0/me/media`,       {         media_type: 'REELS',         video_url: videoUrl, // Publicly accessible URL of the video file         access_token: longLivedToken,       },       {         headers: { 'Content-Type': 'application/json' },       }     )       .then((response) => {         console.log('Reel successfully uploaded:', response.data);         return res.status(200).json({ mediaId: response.data.id });       })       .catch((error) => {         console.error('Error uploading reel:', error.response ? error.response.data : error.message);         return res.status(500).json({ error: 'Failed to upload reel' });       });   }); }); export const publishReel = asyncHandler(async (req: Request, res: Response) => {   const { mediaId, longLivedToken }: any = req.body;   if (!mediaId || !longLivedToken) {     return res.status(400).json({ error: 'Invalid data' });   }   try {     const response = await axios.post(       `https://graph.instagram.com/v20.0/me/media_publish`,       {         creation_id: mediaId,         access_token: longLivedToken,       },       {         headers: { 'Content-Type': 'application/json' }       }     );     return res.status(200).json({ postId: response.data.id }); // Return post ID   } catch (error) {     console.error('Error publishing image:', error.response ? error.response.data : error.message)}      }); 

enter image description here`

Can we create Media template with using Resumable Upload API of Meta, if we have the https url of the media

We wanted the create media template using meta cloud api without using resumable upload api.

eg payload : { "category": "MARKETING", "name": "flig_confim", "language": "en", "allow_category_change": true, "components": [ { "type": "BODY", "text": "This is your flight confirmation for {{1}}-{{2}} on {{3}}", "example": { "body_text": [ [ "Delhi", "Banglore", "20th Monday" ] ] } }, { "type": "FOOTER", "text": "To manage the reservation signin to travel portal" }, { "type": "HEADER", "format": "IMAGE", "example": { "header_handle":"4::YX..." } } ] }

Below is the example to create media template with header_handle info got during resumable api. But we wanted to create media tempate without using resumable api, where user will provide the https url of the image/document and we need to create template using that link instead of header_handle

I'm trying to get comments from Facebook live_videos with Facebook SSE.
Despite I can easily retrieve comments with the {live-video-id}/comments graph api using my test app's page access token, I can't make the SSE to work with the same access token.
Trying to connect with eventsource (code below) keep giving { type: 'error', status: 404, message: 'Not Found' }

async execute() {     this.es = new EventSource(       `https://streaming-graph.facebook.com/${live_video_id}/live_comments?access_token=${page_access_token}`,     );     this.es.onopen = (ev) => {       console.log('onopen', ev);     };     this.es.onmessage = (ev) => {       console.log('onmessage', ev);     };     this.es.onerror = (err) => {       console.error(err);     };   } 

Is there anything else that I'm still missing to get the SSE to work?

I uploaded a photo via WhatsApp, which can be accessed via:

https://graph.facebook.com/v19.0/{imageId} 

Requesting this API returns the URL of the image:

{     "url": "https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid={imageId}&ext={ext}&hash={hash}",     "mime_type": "image/jpeg",     "sha256": "fd9d5ac5bb84b8a0b7a3402c3a99ed9ff3e9fadb4fa567cd101eaf4923d2b375",     "file_size": 667836,     "id": "{imageId}",     "messaging_product": "whatsapp" } 

Then, accessing this URL by Postman successfully returns the image that I uploaded.

However, when I use Nodejs, it returns something that I cannot convert to an image to be displayed on browsers.

const url = (   await axios.get("https://graph.facebook.com/v19.0/{imageId}", {     headers: {       Authorization: `Bearer ${process.env.WHATSAPP_API_KEY}`,     },   }) ).data.url; const image = Buffer.from(   (     await axios.get(url, {       method: "GET",       headers: {         Authorization: `Bearer ${process.env.WHATSAPP_API_KEY}`,       },     })   ).data ).toString("base64"); console.log(image); // 77+977+977+977+9ABBKRklGAAEBAQBgAGAAAO+... 

This prints some base64-encoded string, but when I test it https://base64.guru/converter/decode/image here, it tells that the string represents an application/octet-stream data. Therefore, I cannot display the image in my Remix code.

<img src={`data:image/jpeg;base64,${image}`} /> // not working 

How can I appropriately retrieve the image as base64 from the API?

I’m developing a custom crm in react and nodejs.

I need to integrate a box in which the user/operator can message through whatsapp to the customers.

I read that I can’t use the iframe cause there are some several restrictions.

How can I add this feature?

ps: I don’t want to open new tab in the browser and redirect to whatsapp web.