You can trigger chat message events in one of two ways:
- Client -> Your Server -> Pusher HTTP API -> All clients
- Client -> Pusher WebSocket API -> All Clients
In scenario 1 the messages are going via your own server so you can easily store them in a database.
In scenario 2 you can set up client event WebHooks. Using these the message route is:
Client -> Pusher WebSocket API -> All Clients && WebHook -> You Server
You can then store the client event messages in your database when they arrive via the WebHook.
How to set up a Pusher WebHook
You set up a WebHook for your Pusher App within the dashboard.
Simply choose WebHooks setting for the app.

Create a new "client event" WebHook using an endpoint on your own application as the URL:

The WebHook will be created so any time a client event is triggered for this app that endpoint will be hit.

Consuming a Pusher WebHook
The format of the POST
request to the URL you have defined will be:
{
"name": "client_event",
"channel": "name of the channel the event was published on",
"event": "name of the event",
"data": "data associated with the event",
"socket_id": "socket_id of the sending socket",
"user_id": "user_id associated with the sending socket" # Only for presence channels
}
So, you need to parse the body of the request and get the information you require.
Please be sure to read the WebHook docs and follow the security guidelines.