在WhatsApp Cloud API中将示例图像添加到模板标题中

发布于 2025-02-02 23:55:03 字数 973 浏览 1 评论 0原文

我正在使用WhatsApp Cloud API进行一个项目。我需要使用媒体标题创建模板。我已经创建了一个没有示例图像的媒体标题的模板,并被拒绝。因此,我想在Node.js中创建一个带有示例图像的模板。

带有媒体标题的模板:

“带媒体标头的模板”

添加模板的示例图像:

“添加模板的示例图像”

curl -X POST "https://graph.facebook.com/v14.0/{whatsapp-business-account-ID}/message_templates
  ?name={template-name}
  &language=en_US
  &category=TRANSACTIONAL,
  &components=[{
       type:BODY, 
       text:{message-text}
     }, 
     {
       type:HEADER, 
       format:IMAGE, 
       example:{header_handle:[{uploaded-image-file-url}]}
     }],
  &access_token={system-user-access-token}"

我想使用node.js添加示例图像(不像第二张图片那样)。

I am doing a project using WhatsApp cloud API. I need to create a template with a media header. I have created a template with a media header without a sample image and it gets rejected. So I want to create a template with a sample image in Node.js.

Template with a media header:

Template with a media header

Add sample image for a template:

Add sample image for a template

curl -X POST "https://graph.facebook.com/v14.0/{whatsapp-business-account-ID}/message_templates
  ?name={template-name}
  &language=en_US
  &category=TRANSACTIONAL,
  &components=[{
       type:BODY, 
       text:{message-text}
     }, 
     {
       type:HEADER, 
       format:IMAGE, 
       example:{header_handle:[{uploaded-image-file-url}]}
     }],
  &access_token={system-user-access-token}"

I want to add a sample image using Node.js (not manually like the second picture).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

阪姬 2025-02-09 23:55:03

header_handle需要Facebook提供的加密文件上传。

这可以通过致电2个API来完成。

首先
我们必须创建一个会话,以便上传文件。
要创建会话,请参阅 this

创建会话后,我们将在创建会话后,我们将获取会话ID将原始文件上传到其。反应将看起来像这样:

{“ id”:“上传:mtphdhrhy2htzw50ojlk2mjizxuwlwlwv6mdutndiwmy05yta3lwq4zdpmzgfmzgfkntm0nt8 =?sig =?


这将给出类似的回应

{“ h”:“ 2:c2ftcgxllm1wna ==:image/jpeg:gkaj0gauczmj1vofadip2iiaaaaaaaaabugbaaaa:e:14720755513:arz_3ybzrqqealumudi}

{“ H”:“ 2:C2FTCGXLLM1WNA ==:Image/jpeg :

{header_handle:[“ 2:c2ftcgxllm1wna ==:image/jpeg:gkaj0gauczmj1vofadip2iiaaaaaaaaaaaaaabugbaaaa:e:14720755513:arz_3ybzrzrimudi}

应该在请求期间添加create semplate。

它对我有用。

参见 this ,以更好地了解如何做。

header_handle requires a encrypted file upload provided by facebook.

This can be done by calling 2 apis.

First,
We have to create a session for the file to be uploaded.
For creating session refer this

After creating session, we will get session id to upload the original file to it.Response will look something like this:

{"id":"upload:MTphdHRhY2htZW50Ojlk2mJiZxUwLWV6MDUtNDIwMy05yTA3LWQ4ZDPmZGFkNTM0NT8=?sig=ARZqkGCA_uQMxC8nHKI"}

Second,We have to upload the file to
https://graph.facebook.com/v14.0/{above_id}

This will give a response something similar to

{"h":"2:c2FtcGxlLm1wNA==:image/jpeg:GKAj0gAUCZmJ1voFADip2iIAAAAAbugbAAAA:e:1472075513:ARZ_3ybzrQqEaluMUdI"}

Finally,

{header_handle:["2:c2FtcGxlLm1wNA==:image/jpeg:GKAj0gAUCZmJ1voFADip2iIAAAAAbugbAAAA:e:1472075513:ARZ_3ybzrQqEaluMUdI"]}

Should be added during the request to create template.

It worked for me.

See this for better understanding on how to do it.

各自安好 2025-02-09 23:55:03

Aravindh提供的答案是正确的,您可以关注此文档从元到上传所需的图像。

只需确保您使用WhatsApp API的支持类型(对于 whatsapp业务平台云api ,对于 WhatsApp业务平台本地API )和上传终点( file-type - 文件的MIME类型。有效值为:Image/jpeg,image/image/jpg,image/png和video/mp4

仔细检查您是否正在遵循支持的类型,例如,如果PNG,则需要将“ file_type”设置为“ image/png” no just'juss href =“ https://developers.facebook当创建上传会话。

我已经对其进行了测试,对我有用。

希望这会有所帮助

The answer Provided by Aravindh is correct, you can follow This document from Meta to upload the Image you want.

Just make sure you use a supported type by WhatsApp API ( For WhatsApp Business Platform Cloud API , For WhatsApp Business Platform On-Premises API ) and the upload end point (file-type — The file's MIME type. Valid values are: image/jpeg, image/jpg, image/png, and video/mp4
)

Double Check if you are following exacly the types supported, for example in case of png, you need to set "file_type" to "image/png" no just "png" when creating the upload session.

I have tested it and it works for me.

Hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文