https://discord.gg/botpress logo
Vision agent with Whatsapp
# 🤝help
b
Hello, i am trying to get the vision agent on an autonomous node to work with whatsapp. the issue seems to be that the vision agent is currently unable to access the url of the whatsapp image. from my understanding, it seems that there are some pre-processing steps to do. I am currently using an Autonomous agent with the vision card, so i am not sure how to preprocess the item whenever an image is received or how to do the preprocessing step, given that at any time in the conversation the user can send an image. @orange-egg-72655 as reviewed during office hours, would you be able to help? Thank you!
o
You need your whatsapp access token to access images from the url being generated. Store it in a configuration variable and then have execute code card that fetches the image with the token. I.e. using axios.get with the image url and using your whtsapp token as the authorization in the headers
Copy code
js
const response = await axios.get(url, {
  headers: {
    Authorization: `Bearer ${env.accessToken}`
  },
  responseType: 'arraybuffer'
});
and then you would have to use files api to upload
b
but i am using an autonomous node to handle the conversation
o
Create an action!

https://www.youtube.com/watch?v=fmYYZteKKg8▾

create an action that does what I wrote above. And pass the action to the autonomous node and specify that when an image is sent, to call the action
b
will i be able to access the vision card in an action?
because once i get the image, i need to pass it to the vision agent
o
the action is for getting the image without having a restricted url (one that you cannot access without a token). Return the proper URL / image to the autonomous node via the action card and the autonomous node should then act the same way it was acting in your emulator
The only reason it works for emulator but not whatsapp right now is because the autonomous node cannot see the content of the file as whatsapp/meta is restricting it behind an access token
b
Thanks matthew, i will try this approach
o
Let me know how it goes!
b
@orange-egg-72655 It works, thank you!
o
I'm glad it worked!
s
@orange-egg-72655 I did this to extract the image and then save it as base64. I'm using StandardNode and after execute code card I'm calling AI generate text card to use the image description. How do I trigger the Vision Agent so that it uses this image. here's my code : // 1) Grab your WhatsApp signed URL & PAC const imageUrl = event.payload.imageUrl const token = env.WHP_ACCESS_TOKEN if (!imageUrl) throw new Error('Missing imageUrl') if (!token) throw new Error('Missing WHP_ACCESS_TOKEN') // 2) Parse the
mid
query param as your media ID const urlObj = new URL(imageUrl) const mediaId = urlObj.searchParams.get('mid') if (!mediaId) throw new Error('Could not extract mediaId from imageUrl') // 3) Exchange mediaId for a fresh download URL const infoRes = await axios.get(
https://graph.facebook.com/v19.0/${mediaId}
, { headers: { Authorization:
Bearer ${token}
} } ) const downloadUrl = infoRes.data.url if (!downloadUrl) throw new Error('No download URL returned by Graph API') // 4) Fetch the bytes from that URL const fileRes = await axios.get(downloadUrl, { headers: { Authorization:
Bearer ${token}
}, responseType: 'arraybuffer' }) // 5) Turn it into Base64 + capture MIME type const mimeType = fileRes.headers['content-type'] const base64Image = Buffer.from(fileRes.data, 'binary').toString('base64') // 6) Store for your Vision/LLM card workflow.fileType = mimeType workflow.base64Img = base64Image console.log(
[ImageAnalysis] got ${mimeType}, base64-length=${base64Image.length}
) const dataUri = `data:${mimeType};base64,${base64Image}`; workflow.encodedImage = dataUri;
9 Views