ruby_whatsapp_sdk icon indicating copy to clipboard operation
ruby_whatsapp_sdk copied to clipboard

Add location header to templates

Open ignacio-chiazzo opened this issue 1 year ago • 3 comments

The API just released, adding the location to the template via headers:

API responses to template creation and editing requests now include the template's status and category.

ignacio-chiazzo avatar Mar 19 '23 16:03 ignacio-chiazzo

Let me in @ignacio-chiazzo

Aaryanpal avatar Mar 20 '23 14:03 Aaryanpal

Sure @Aaryanpal!

The template API code lives in the messages_api file.

Let me know if you need help. My DMs are open in TW https://twitter.com/ignaciochiazzo

ignacio-chiazzo avatar Mar 20 '23 14:03 ignacio-chiazzo

@Aaryanpal have you had a chance to look at it?

ignacio-chiazzo avatar Apr 16 '23 23:04 ignacio-chiazzo

Hey @ignacio-chiazzo

I see this issue has been stale for quite some time, and I'd like to take a peek. I'm still learning the ropes of the API and this codebase. So, to clarify a bit on the ask

Is this the approach you'd like to have when sending templates with location headers?

Let me know if I'm on the right track or missing something

location = WhatsappSdk::Resource::Location.new(
  latitude: 25.779510,
  longitude: -80.338631,
  name: "My Miami Store",
  address: "820 NW 87th Ave, Miami, FL"
)
location_parameter = WhatsappSdk::Resource::ParameterObject.new(type: "location", location: location)
location_component = WhatsappSdk::Resource::Component.new(
  type: WhatsappSdk::Resource::Component::Type::Header,
  parameters: [location_parameter]
)

messages_api.send_template(
  sender_id: 123,
  recipient_number: 123,
  name: "location_test",
  language: "en_US",
  components: [location_component]
)

piscespieces avatar Jun 03 '24 18:06 piscespieces

I haven't tried myself but the API says you need to specify the format: Location

Screenshot 2024-06-05 at 12 14 39 PM

official docs: https://developers.facebook.com/docs/whatsapp/business-management-api/message-templates/components#location-headers

Feel free to open a PR with the changes and a test case.

ignacio-chiazzo avatar Jun 05 '24 15:06 ignacio-chiazzo

Yeah, when creating a template with a location header you must pass the `"format": "location"

However, you don't have to when sending a template—I'll open a PR, and we can continue the discussion there.

Here's the sending a template with location docs for reference

piscespieces avatar Jun 05 '24 19:06 piscespieces