How to console.log google maps location link, whic...
# 🤝help
p
Initially i have declared string and add raw input card.
f
Hey there, Could you describe what you are trying to do, and what you have tried to do to fix the issue.
p
Hello, in a whatsapp, i sharing current location link, i want to extract few parameters from that shared link, i have tried with raw input and address card, data type of variable i kept are string, object, array, things it's not getting captured, again and again ask for input in loop.
to inspect, i have getting input message as a arrays of object,
Copy code
Handler 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" attributes
how to capture it
@fresh-fireman-491
f
Ah okay. I am not that familiar with WhatsApp so I have just create a sample payload instead.
Copy code
javascript
// 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"
        }
      ]
    }
  ]
};
Copy code
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);
Logs this:
Copy code
{ address: 'abc, 560',
  latitude: 'xxxx',
  longitude: 'xxxx',
  name: 'Gxxx',
  url: 'https://foursquare.com/v/wewwer' }
p
@User things is i'm not able to capture above info from prompt, there is overview of flow variable : locationlink, type :string added the raw input card to capture the address, but raw input card is repeating again and again in loop. also tried with history -1 , with raw input no luck capturing it trail 2 removed raw input card and added the full address card and made variable as type object again the full address card is repeating in a loop tried with multiple choice card also here is prompt i'm getting
Copy code
May 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."
i can see an object payload in my prompt, but why botpress is ignoring it? not capturing the user input message.
f
Could you take a screenshot of a conversation where it's unable to capture it.
@User Both are the screen shots, receiving the object as message, i using raw input and full address, both the cards are ignoring it
f
Try and add a text card after the raw input card with the variable that you store their response in
25 Views