0

I am using the Google Chat card api to send a card back to a user to answer their questions. I wish to include an image within the results, however a direct URL cannot be provided since it is only exposed to the company network.

Instead I have attempted to do the following:

"image": {
    "imageUrl": "data:image/png;base64, ... ",
    "onClick": {
         "openLink": {
            "url": "https://example.com/"
        }
    }
}

However, I am receiving the following error message: <HttpError 400 when requesting https://chat.googleapis.com/v1/spaces/XXXXXXXXXXX/messages?alt=json returned "Request contains an invalid argument.". Details: "Request contains an invalid argument.">.

Is there any way I could send images using the Google Chat API that doesn't involve uploading the images to the public first, or am I doing something wrong with my implementation? The issue is not that the string is too long as the base 64 string that I am trying to send over is quite short.

The message is being sent from a python server, not from the online JavaScript based editor.

  • Are you sure that your image Url is encoded corerctly, as in the [example](https://developers.google.com/apps-script/reference/card-service/card-header#setimageurlimageurl): `var encodedImageURL = "data:image/jpeg;base64," + Utilities.base64Encode(imageBytes);`? – ziganotschka Oct 26 '22 at 13:39
  • The link you sent is not for the Google Chat API. It's for Google Workspace Addons. And even if it were applicable, what is the difference between the encodings? jpeg vs png? – Michael Pulis Oct 28 '22 at 07:15
  • My question was about either you are sure that your imageURL is encoded correctly (I was not referring to the `data:image/png;base64,` part, but to the `...` part). – ziganotschka Oct 28 '22 at 11:09
  • When I take the entire base 64 encoded image, open Chrome's debugger, and manually paste it into an `` tag's `src`, it displays properly. Thus, I think the encoding is correct. It's just that it's stopped by Google with the error message provided, leading me to believe that they wrote some pattern to validate the `imgUrl` and they did not consider/allow base 64 encoded images. – Michael Pulis Oct 28 '22 at 13:39

1 Answers1

0

It is currently not possible to include base64-encoded images instead of providing an imageURL within a Google Chat Card

A feature request to change this has already been filed on Google's Issue Tracker.

Currently this feature request is still under review and the best thing you can do is to "star" it to show that you are also interested in the implementation and thus increase visibility.

In the meantime, unfortunately there is no workaround to uploading and hosting the image.

ziganotschka
  • 25,866
  • 2
  • 16
  • 33