async function handleGameInsert()

in source/functions/gameupdates-notifications-function/index.js [49:83]


async function handleGameInsert(unmarshalledNewImage, eventID) {
    console.log('new game event detected, checking config for event to notify');
    console.log('unmarshalled is: ');
    console.log(unmarshalledNewImage);
    if(unmarshalledNewImage.type != null && notificationConfig.allowedEvents.indexOf(unmarshalledNewImage.type) != -1) {
        console.log('event will be notified');
        var segmentId = await createSegment(unmarshalledNewImage, eventID);
        console.log('creating campaing');
        var createCampaignResult = await pinpoint.createCampaign({
            ApplicationId: pinpointAppID,
            WriteCampaignRequest: {
                Schedule: {
                    StartTime: "IMMEDIATE"
                },
                Name: "GameEvent#" + eventID + '#' + unmarshalledNewImage.id,
                SegmentId: segmentId,
                MessageConfiguration: {
                    DefaultMessage: {
                        Action: "OPEN_APP",
                        Body: "" + unmarshalledNewImage.awayScore + '-' + unmarshalledNewImage.homeScore + ' ' + unmarshalledNewImage.commentary,
                        Title: "away@home"
                    }
                }
            }
        }).promise();
        console.log('created campaign');
        console.log(createCampaignResult);  
        return {
            segmentId: segmentId,
            campaign: createCampaignResult.data.CampaignResponse
        } 
    } else {
        return null;
    }
};