purple-dog-82741
05/20/2024, 5:41 AMfresh-fireman-491
05/20/2024, 6:04 AMpurple-dog-82741
05/20/2024, 6:37 AMpurple-dog-82741
05/20/2024, 6:37 AMpurple-dog-82741
05/20/2024, 6:40 AMHandler received request from Whatsapp with payload: {"object":"whatsapp_business_account","entry":[{"id":"3","changes":[{"value":{"messaging_product":"whatsapp","metadata":{"display_phone_number":"xxxx","phone_number_id":"2"},"contacts":[{"profile":{"name":"Groot"},"wa_id":"xxxx"}],"messages":[{"from":"91xxxxxx","id":"wamid.DQUVBRTFENTA3MzcA","timestamp":"1716186330","location":{"address":"abc, 560","latitude":xxxx,"longitude":xxxx,"name":"Gxxx","url":"https:\/\/foursquare.com\/v\/wewwer"},"type":"location"}]},"field":"messages"}]}]}
this is log when i upload the location link, i want to extract the "location" attributespurple-dog-82741
05/20/2024, 6:40 AMpurple-dog-82741
05/20/2024, 7:01 AMfresh-fireman-491
05/20/2024, 1:36 PMjavascript
// Sample payload
const payload = {
"object": "whatsapp_business_account",
"entry": [
{
"id": "3",
"changes": [
{
"value": {
"messaging_product": "whatsapp",
"metadata": {
"display_phone_number": "xxxx",
"phone_number_id": "2"
},
"contacts": [
{
"profile": {
"name": "Groot"
},
"wa_id": "xxxx"
}
],
"messages": [
{
"from": "91xxxxxx",
"id": "wamid.DQUVBRTFENTA3MzcA",
"timestamp": "1716186330",
"location": {
"address": "abc, 560",
"latitude": "xxxx",
"longitude": "xxxx",
"name": "Gxxx",
"url": "https://foursquare.com/v/wewwer"
},
"type": "location"
}
]
},
"field": "messages"
}
]
}
]
};
javascript
// Function to extract location information
function extractLocation(payload) {
try {
const entry = payload.entry[0];
const change = entry.changes[0];
const message = change.value.messages[0];
if (message.type === 'location') {
const location = message.location;
return {
address: location.address,
latitude: location.latitude,
longitude: location.longitude,
name: location.name,
url: location.url
};
} else {
throw new Error("No location message found");
}
} catch (error) {
console.error("Error extracting location:", error.message);
return null;
}
}
// Extract location data
const locationData = extractLocation(payload);
console.log(locationData);
fresh-fireman-491
05/20/2024, 1:36 PM{ address: 'abc, 560',
latitude: 'xxxx',
longitude: 'xxxx',
name: 'Gxxx',
url: 'https://foursquare.com/v/wewwer' }
purple-dog-82741
05/21/2024, 4:52 AMMay 21, 2024, 10:08:05 AM
[219c15947a] [agent-hook] [KnowledgeAgent] [conversation_turn_started]: Skipping KB: turn has no message
May 21, 2024, 10:08:05 AM
[219c15947a] [bot-hook] [after_incoming_middleware] [Tokens]: Executing hook
May 21, 2024, 10:08:05 AM
[219c15947a] [dm] : [Capture] All properties of the extracted object are null, which means the user probably didn't answer the question.
May 21, 2024, 10:08:05 AM
[219c15947a] [dm] : [Capture] Field extraction failed. Input:
May 21, 2024, 10:08:05 AM
[219c15947a] [dm] : [Capture] Extraction failed (2/2 attempts)
May 21, 2024, 10:08:05 AM
[219c15947a] [dm] : [Capture] Prompt failed. Maximum number of retries reached.
May 21, 2024, 10:08:05 AM
[219c15947a] [dm] : [Capture] Prompt failed
May 21, 2024, 10:08:05 AM
[219c15947a] [bot-action] [flow:Menu] [node:Standard4] [card:Logging the address link in the workflow.]: Execute code "Logging the address link in the workflow."
purple-dog-82741
05/21/2024, 4:53 AMfresh-fireman-491
05/21/2024, 7:33 AMpurple-dog-82741
05/21/2024, 7:38 AMpurple-dog-82741
05/21/2024, 7:39 AMfresh-fireman-491
05/21/2024, 11:16 AM