ignacio-chiazzo / ruby_whatsapp_sdk

A lightweight, efficient Ruby gem for interacting with Whatsapp Cloud API.
https://ignacio-chiazzo.github.io/ruby_whatsapp_sdk/
MIT License
156 stars 33 forks source link

Add location header to templates #85

Closed ignacio-chiazzo closed 4 weeks ago

ignacio-chiazzo commented 1 year ago

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.

Aaryanpal commented 1 year ago

Let me in @ignacio-chiazzo

ignacio-chiazzo commented 1 year ago

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 commented 1 year ago

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

piscespieces commented 1 month ago

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]
)
ignacio-chiazzo commented 1 month ago

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.

piscespieces commented 1 month ago

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