Get payload info in workflow variables!!
# 🤝help
e
Hello ! I wanted to ask if it is possible to get the payload of each message sent by user on WhatsApp ? I want to be able to retrieve the number of the user that sent a message. In the logs of BotPress, I see that the info I am looking for is available : "recipient_id" Is it possible through the BotPress Cloud ? Thank you ! https://cdn.discordapp.com/attachments/1242828500767870997/1242828501107736669/image.png?ex=664f41bd&is=664df03d&hm=e60c36f262c3bd02a91a7336a6f20e883e7b57301a36ddc813e3857e9a1c86e3&
f
Hey there, You can probably get it from
event.payload
Can you try
Copy code
javascript
const recipientId = event.payload.entry[0].changes[0].value.statuses[0].recipient_id;
console.log('Recipient ID:', recipientId);
You should be able to see it in the logs then
e
will try now
f
Also. Can you add console.log(event.payload) to the code.
e
sure will do
[card:Extract recipient ID from event payload and log it.]: Error executing action "inline-card:Extract recipient ID from event payload and log it..js" in flow:Main:node:text [Error, Cannot read properties of undefined (reading '0') Transpiled Code: 003 var __defProp = Object.defineProperty; 004 var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); 005 async function __ROOT__() { > 006 const recipientId = event.payload.entry[0].changes[0].value.statuses[0].recipient_id; ^^^^^^^^^^ 007 console.log("Recipient ID:", recipientId); 008 ; 009 } 010 __name(__ROOT__, "__ROOT__"); > 011 ; return await __ROOT__(); ^^^^^^^^^^ ]
GOT THIS ERROR, BRO @fresh-fireman-491
f
Maybe you can try to just console.log(event.payload)
You are testing it via WhatsApp, right?
e
yes
will try log first
man, this is only the payload: Event Payload: { text: 'Hellooooo' }
f
Maybe a @User or @limited-pencil-78283 knows
e
That would be great guys, thanks a million
l
you want to get payload or retrieve the number of users that sent a message?
e
Yes user details, phone number, name etc
e
yes and the names
it's already in the conversation tap
f
Ah okay. Phone number:
{{ event.tags.conversation['whatsapp:userPhone'] }}
Maybe Lijo knows about the name
l
workflow.existingUser = false user.phoneNumber = event.tags.conversation['whatsapp:userPhone'] user.conversationID = event.conversationId user.fullName = event.tags.user['whatsapp:name'] const conversationIdRecord = await ConversationIdTable.findRecords({ filter: { phoneNumber: user.phoneNumber } }) if (conversationIdRecord.length === 0) { await ConversationIdTable.createRecord({ phoneNumber: user.phoneNumber, conversationID: user.conversationID, userName: user.fullName }) }
f
Amazing!!!
e
Finallyy... this for whatsapp only right?
Anything for messenger ?
l
I have created a table ConversationIdTable have three columns phoneNumber, conversationID, userName. this code is next after START and checks if the user phone number is present in the table and if not add it
Yes for WA only
Have not tried, but try and let me know
e
Super smart
l
event.payload keep working with it
e
you mean that it has also messenger data?
l
everything is there in event.payload, just need to keep expanding each object to find details
e
thanks man will try it and get back
l
sure do share if you find for messenger
happy to learn
e
will do definetly
79 Views