messagebird / messagebird-nodejs

The open source Node.js client for MessageBird's REST API
https://www.messagebird.com/developers
105 stars 44 forks source link

Cannot send HSM template with header video #101

Closed ArkjuniorK closed 2 years ago

ArkjuniorK commented 2 years ago

messagebird-nodejs unable to sent message template with media video. Also the interface of hsm did not had the video type for header so when we use snippet below the type key would throw an error.

   msgbird.conversations.send(
        {
          to: phone_number,
          from: "xxxxxx_xxxxxxxxx",
          type: "hsm",
          content: {
            hsm: {
              namespace: "xxxxxxxx_xxxxxxxxx",
              templateName: "template_video",
              language: { policy: "deterministic", code: "id" },
              components: [
                {
                  type: "header",
                  parameters: [
                    {
                      type: "video",
                      video: {
                        url: "https://example.com/media/videoplayback.mp4",
                      },
                    },
                  ],
                },
                {
                  type: "body",
                  parameters: [...],
                },
              ],
            },
          },
          reportUrl: "https://example/log/repot",
        },
        function (err, res) {
          if (err) {
            log.error("Error [" + body.phone_number + "]", err.message);
          }
          log.log("Success [" + body.phone_number + "]");
        }
      );

We are using Typescript for our codebase. So adding video type for HSMComponentParameter[] should fix the problem with syntax but still the message did not sent to the user. Is there something we should do? Or it is not supported yet? Thanks for the advice.

aodinok commented 2 years ago

Hi @ArkjuniorK, thanks for reporting the bug.

I've added missing TypeScript types to HSMComponentParameter, and asked our support why video doesn't work for you. I will let you know once I have more details

ArkjuniorK commented 2 years ago

I've added missing TypeScript types to HSMComponentParameter, and asked our support why video doesn't work for you. I will let you know once I have more details

Thank you.

aodinok commented 2 years ago

@ArkjuniorK our support get back to me, and they confirmed that it should work for you.

Here is example curl command to API:

curl -X "POST" "https://conversations.messagebird.com/v1/send" \
     -H 'Authorization: AccessKey ...' \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d $'{
  "content": {
    "hsm": {
      "language": {
        "code": "en"
      },
      "components": [
        {
          "type": "header",
          "parameters": [
            {
              "type": "video",
              "video": {
                "url": "URL_TO_VIDEO"
              }
            }
          ]
        },
        {
          "type": "body",
          "parameters": [
            {
              "type": "text",
              "text": "SOME TEXT"
            },
            {
              "type": "text",
              "text": "ANOTHER TEXT"
            }
          ]
        }
      ],
      "namespace": "NAMESPACE_ID",
      "templateName": "TEMPLATE_NAME"
    }
  },
  "to": "+PHONE_NUMBER",
  "type": "hsm",
  "from": "CONTACT_ID"
}'
ArkjuniorK commented 2 years ago

Here is example curl command to API:

Thanks for your answer. So we should use the curl to send media video instead of Node SDK?

aodinok commented 2 years ago

No! This is just example of how to structure the request body.

Also the way to confirm that problem is not with SDK if your curl attempt will not work. If it works - problem is with SDK and we will dig deeper together to try to find it.

Can you please try to use curl and let me know the results?

ArkjuniorK commented 2 years ago

Here is example curl command to API:

I tried the code and still did not work. My message keep rejected when I check the Inbox

aodinok commented 2 years ago

So this means it is something with your call and not nodejs SDK. Can you please reach out to MessageBird support? https://support.messagebird.com/hc/en-us/requests/new?ticket_form_id=1900000147753 They should be able to help you better, I do not have the means to test your call or access to your details. I will push the changes with a TS typings fix.

ArkjuniorK commented 2 years ago

So this means it is something with your call and not nodejs SDK. Can you please reach out to MessageBird support? https://support.messagebird.com/hc/en-us/requests/new?ticket_form_id=1900000147753 They should be able to help you better, I do not have the means to test your call or access to your details. I will push the changes with a TS typings fix.

Thanks for your feedback