waha icon indicating copy to clipboard operation
waha copied to clipboard

[Feature Request] Support to S3 file storage

Open pablomorato1 opened this issue 1 year ago • 8 comments

On my application is necessary to store the media sent on a message on S3 right when my Waha client receives the message to because I use SQS to handle the requests and ensure the delivery of all messages on a server downtime.

I'd like to have a plug and play feature that make possible to deliver the media data directly to my S3 bucket, and have the file url for it returned instead of the local_storage file url.

Is there already any way to do it?

pablomorato1 avatar May 30 '24 12:05 pablomorato1

Not yet, but we'll add it, shouldn't be a problem!

patron:PRO

allburov avatar May 31 '24 03:05 allburov

+1

patron:PRO

arielpts avatar Jul 08 '24 19:07 arielpts

+1

HuangDaHui avatar Jul 11 '24 03:07 HuangDaHui

+1

mohammadkurdi avatar Jul 12 '24 17:07 mohammadkurdi

+1

shivkodam avatar Jul 18 '24 09:07 shivkodam

+1

patron:PRO

puntorigen avatar Jul 18 '24 20:07 puntorigen

+1

patron:PRO

meovary150 avatar Aug 02 '24 06:08 meovary150

+1

melquisedeque-magalhaes avatar Aug 09 '24 03:08 melquisedeque-magalhaes

S3 support will be added in 2024.9.1 version :crossed_fingers:

patron:PRO

devlikepro avatar Aug 21 '24 11:08 devlikepro

  • 1

marcelomanchester avatar Aug 21 '24 16:08 marcelomanchester

+1

chardea avatar Aug 26 '24 09:08 chardea

https://waha.devlike.pro/docs/how-to/storages/#media---s3

Media - S3

You can use the S3 storage to store the media files.

Any S3 Compatible storage can be used, such as AWS S3, MinIO, DigitalOcean Spaces, etc. For in-house solutions, you can use MinIO.

Configuration

  • WAHA_MEDIA_STORAGE=S3 - enable the S3 storage
  • WAHA_S3_REGION=eu-west-1 - the region of the S3 bucket
  • WAHA_S3_BUCKET=waha - the name of the S3 bucket
  • WAHA_S3_ACCESS_KEY_ID=minioadmin - the access key of the S3 bucket
  • WAHA_S3_SECRET_ACCESS_KEY=minioadmin - the secret access key of the S3 bucket
  • WAHA_S3_ENDPOINT=http://127.0.0.1:9000 - the endpoint of the S3 bucket (not required for AWS S3)
  • WAHA_S3_FORCE_PATH_STYLE=True - force path style for the S3 bucket (not required for AWS S3)
  • WAHA_S3_PROXY_FILES - proxy media files through WAHA (False by default)
    • WAHA_S3_PROXY_FILES=False - generate pre-signed URLs for media files and send them to the client in media.url
    • WAHA_S3_PROXY_FILES=True - WAHA will proxy media files through itself in media.url

After you enabled S3 here's example for message webhook payload:

{
  "event": "message",
  "session": "default",
  "engine": "WEBJS",
  "payload": {
    "id": "[email protected]_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
    "hasMedia": true,
    "media": {
        "url": "http://localhost:3000/api/files/[email protected]_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.jpg",
        "mimetype": "image/jpeg",
        "filename": null,
        "s3": {
            "Bucket": "bucket-name",
            "Key": "/default/[email protected]_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.jpg"
        },
        "error": null // if there was an error during file download
    }
    ...
  }
}

in addition to media.* field it will have media.s3.* field with the S3 bucket information.

S3 Metadata

Each file saved in S3 has additional metadata:

  • X-Amz-Meta-Waha-Session=default - the session name
  • X-Amz-Meta-Waha-Message-Id=true_111... - the message ID
  • X-Amz-Meta-Waha-Media-File-Name=media.jpg - the media file name (if available)

patron:PRO

devlikepro avatar Aug 27 '24 11:08 devlikepro

In 2024.9.1 https://waha.devlike.pro/docs/overview/changelog/#20249

patron:PRO

devlikepro avatar Aug 27 '24 11:08 devlikepro

https://waha.devlike.pro/docs/how-to/storages/#media---s3

Media - S3

You can use the S3 storage to store the media files.

Any S3 Compatible storage can be used, such as AWS S3, MinIO, DigitalOcean Spaces, etc. For in-house solutions, you can use MinIO.

Configuration

  • WAHA_MEDIA_STORAGE=S3 - enable the S3 storage

  • WAHA_S3_REGION=eu-west-1 - the region of the S3 bucket

  • WAHA_S3_BUCKET=waha - the name of the S3 bucket

  • WAHA_S3_ACCESS_KEY_ID=minioadmin - the access key of the S3 bucket

  • WAHA_S3_SECRET_ACCESS_KEY=minioadmin - the secret access key of the S3 bucket

  • WAHA_S3_ENDPOINT=http://127.0.0.1:9000 - the endpoint of the S3 bucket (not required for AWS S3)

  • WAHA_S3_FORCE_PATH_STYLE=True - force path style for the S3 bucket (not required for AWS S3)

  • WAHA_S3_PROXY_FILES - proxy media files through WAHA (False by default)

    • WAHA_S3_PROXY_FILES=False - generate pre-signed URLs for media files and send them to the client in media.url
    • WAHA_S3_PROXY_FILES=True - WAHA will proxy media files through itself in media.url

After you enabled S3 here's example for message webhook payload:

{
  "event": "message",
  "session": "default",
  "engine": "WEBJS",
  "payload": {
    "id": "[email protected]_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
    "hasMedia": true,
    "media": {
        "url": "http://localhost:3000/api/files/[email protected]_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.jpg",
        "mimetype": "image/jpeg",
        "filename": null,
        "s3": {
            "Bucket": "bucket-name",
            "Key": "/default/[email protected]_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.jpg"
        },
        "error": null // if there was an error during file download
    }
    ...
  }
}

in addition to media.* field it will have media.s3.* field with the S3 bucket information.

S3 Metadata

Each file saved in S3 has additional metadata:

  • X-Amz-Meta-Waha-Session=default - the session name
  • X-Amz-Meta-Waha-Message-Id=true_111... - the message ID
  • X-Amz-Meta-Waha-Media-File-Name=media.jpg - the media file name (if available)

patron:PRO

Can I use Azure Blobs?

HuangDaHui avatar Sep 02 '24 06:09 HuangDaHui

Can I use Azure Blobs?

If there's S3 compatible interface - yes! but I don't think so https://learn.microsoft.com/en-us/answers/questions/1183760/s3-api-support-over-azure-blob-storage

However, you can use an S3-to-Azure gateway https://portal.azure.com/#create/flexify.azure-s3-apice

patron:PRO

devlikepro avatar Sep 03 '24 06:09 devlikepro

我可以使用 Azure Blob 吗?

如果有 S3 兼容接口 - 是的! 但我不这么认为https://learn.microsoft.com/en-us/answers/questions/1183760/s3-api-support-over-azure-blob-storage

但是,您可以使用 S3 到 Azure 网关 https://portal.azure.com/#create/flexify.azure-s3-apice

赞助人:PRO

ok let me look into it thank you very much

HuangDaHui avatar Sep 03 '24 06:09 HuangDaHui

hello, i have a question If I use S3 to store media attachments, will the attachment be re-downloaded when I request this interface? downloadMedia=true /api/messages?chatId=11111111111%40c.us&downloadMedia=true&limit=1&session=default

HuangDaHui avatar Sep 06 '24 06:09 HuangDaHui

will the attachment be re-downloaded

Hi! With all media storages it'll first check if the file is already in the storage and after that download or just return url from the existing file, so you can safely request it over and over, it will not re-download files multiple time if you're asking about that!

patron:PRO

devlikepro avatar Sep 06 '24 06:09 devlikepro

will the attachment be re-downloaded

Hi! With all media storages it'll first check if the file is already in the storage and after that download or just return url from the existing file, so you can safely request it over and over, it will not re-download files multiple time if you're asking about that!

patron:PRO

Okay, but I encountered a problem recently. When I requested this interface, I got 20 messages and still couldn't get the result after more than 20 minutes.

/api/messages?chatId=11111111111%40c.us&downloadMedia=true&limit=20&session=default Error: response status is 524

HuangDaHui avatar Sep 06 '24 06:09 HuangDaHui

will the attachment be re-downloaded

Hi! With all media storages it'll first check if the file is already in the storage and after that download or just return url from the existing file, so you can safely request it over and over, it will not re-download files multiple time if you're asking about that! patron:PRO

Okay, but I encountered a problem recently. When I requested this interface, I got 20 messages and still couldn't get the result after more than 20 minutes.

/api/messages?chatId=11111111111%40c.us&downloadMedia=true&limit=20&session=default Error: response status is 524

I don’t know why, but it keeps getting 524, so I want to try S3 to see if it can solve this situation.

HuangDaHui avatar Sep 06 '24 06:09 HuangDaHui

@HuangDaHui hi! Could you send us your discord please so we can find out the problem with 20 messages? It should work like in a minute, even if all 20 messages would have simple image [email protected]

patron:PRO

devlikepro avatar Sep 07 '24 07:09 devlikepro

@HuangDaHui hi! Could you send us your discord please so we can find out the problem with 20 messages? It should work like in a minute, even if all 20 messages would have simple image [email protected]

patron:PRO

Hi, I sent you an email but I don't know how to contact you using Discord.

HuangDaHui avatar Sep 09 '24 03:09 HuangDaHui