Webhooks
Track GamePush events via Webhooks.
You will need to receive notifications on your server, for example, when processing payments. We will notify you when a player makes a payment so that you can process the purchase and award the player.
Add Webhook
First, you need to add a secret key to verify the authenticity of notification data.
- Go to Project > Public Zone
- In the Secret Key field, click "Create Key".
Now create a Webhook:
- Go to Project > Trusted Sites > Webhooks
- In the Webhooks section, create a Webhook.
- Specify the link that will receive requests from our server.
- If you need to track test requests, check the "Dev" box.
- Through the "Notification Settings" button, select the notifications you need us to send.
- Add the Webhook.
Concept
The webhook is sent via http
protocol using the POST
method in Base64
format, containing JSON
.
For every player action marked by you, we send data to your server in Base64
format containing JSON
, for example:
{
"event": "GivePlayerReward",
"player": {
"id": 1820283,
"name": "",
"avatar": "",
"projectId": 4,
"credentials": "",
"platformType": "NONE",
"active": true,
"removed": false,
"test": false,
"modifiedAt": "2024-04-26T11:34:23.415923998Z"
},
"result": {
"__typename": "PlayerReward",
"countAccepted": 0,
"countTotal": 1,
"rewardId": 685
},
"time": "2024-04-26T11:34:23.415923998Z"
}
Payload fields:
event
- event type.player
- the player on whose behalf the request was made.result
- operation result. Unlike the API, we do not notify on error. A successful action result always comes.time
- time of the operation.
All result types are available in introspection. All hooks return the same operation result as the API response. To view the schema or work in a sandbox, use the Chrome extension - Altair GraphQL Client.
API is available at
https://api.gamepush.com/gs/api/graphql
Getting the Result
The result comes in Base64
with a signature separated by .
, for example:
eyJ2YWx1ZSI6ICJzb21lIHJlYWwgZGF0YSJ9.cmVhbHNlY3JldGtleQ==
The first part is the request data, the second part is the signature.
Example of extracting data in JavaScript:
const body = 'eyJ2YWx1ZSI6ICJzb21lIHJlYWwgZGF0YSJ9.cmVhbHNlY3JldGtleQ==';
const [base64payload, signature] = body.split('.');
const payload = JSON.parse(atob(base64payload));
console.log(payload.event);
Signature Verification
Make sure the request was made specifically from our server. You will need the secret key
you created earlier.
To verify the signature, compare your SHA256 hash with what came in the hook.
The SHA256 signature is formed from the string:
base64payload_secretKey
base64payload
- the first part of the request before.
;secretKey
- your secret token created specifically for the project.
Example of signature verification in JavaScript:
// Import library for creating signatures
import crypto from 'crypto';
// Your project's secret key
const secretKey = 'Be$T_Pr0jeCt';
// Data of the request sent by the GamePush server
const body = 'eyJ2YWx1ZSI6ICJzb21lIHJlYWwgZGF0YSJ9.cmVhbHNlY3JldGtleQ==';
// Get payload and signature from the body
const [base64payload, signature] = body.split('.');
// Prepare data for signing
const signData = `${base64payload}_${secretKey}`;
// Create signature
const hash = crypto.createHash('sha256').update(signData);
// Compare the signature
if (hash !== signature) {
// Someone is being tricky
res.status(400);
res.send('Bad request');
return;
}
// Get data and continue working
const payload = JSON.parse(atob(base64payload));
console.log(payload.event);
Events
Event Type | Description |
---|---|
PurchasePlayerPurchase | Player made a purchase / subscribed |
ConsumePlayerPurchase | Player consumed purchase |
UnsubscribePlayerSubscription | Player unsubscribed from subscription |
ResumePlayerSubscription | Player resumed subscription |
ExpirePlayerSubscription | Player's subscription expired |
UnlockPlayerAchievement | Player unlocked an achievement |
PlayerSetAchievementProgress | Player set achievement progress |
PlayerPublishRecord | Player published a record |
SyncPlayer | Player synchronized progress |
GetPlayer | Player loaded progress |
GivePlayerReward | Player rewarded |
PlayerSendInviteToChannel | Player sent an invitation to a channel |
PlayerCancelInviteToChannel | Player canceled an invitation to a channel |
PlayerAcceptInviteToChannel | Player accepted an invitation to a channel |
PlayerRejectInviteToChannel | Player rejected an invitation to a channel |
PlayerJoinChannel | Player joined a channel |
PlayerLeaveChannel | Player left a channel |
PlayerCancelJoinChannel | Player canceled a join request to a channel |
PlayerAcceptJoinRequestToChannel | Player accepted a join request to a channel |
PlayerRejectJoinRequestToChannel | Player rejected a join request to a channel |
PlayerKickFromChannel | Player kicked another player from a channel |
PlayerSendPersonalMessage | Player sent a personal message |
PlayerSendFeedMessage | Player sent a message to a channel |
PlayerSendMessage | Player sent a message |
PlayerEditMessage | Player edited a message |
PlayerDeleteMessage | Player deleted a message |
PlayerMutePlayerInChannel | Player muted in a channel |
PlayerUnmutePlayerInChannel | Player unmuted in a channel |
PlayerCreateChannel | Player created a channel |
PlayerUpdateChannel | Player updated a channel |
PlayerDeleteChannel | Player deleted a channel |
UploadPlayerFile | Player uploaded a file |
UploadPlayerImage | Player uploaded an image |
Stay in Touch
Other documents of this chapter available Here. To get started, welcome to the Tutorials chapter.
GamePush Community Telegram
: @gs_community.
For your suggestions e-mail
: [email protected]
We Wish you Success!