Alexa notification anouncement (proactive events)

amazon-alexa

#1

Alexa proactive events implemented and it is not having any error but the notification is not showing.my project .js

module.exports = {
    alexaSkill: {
        nlu: 'alexa',
        manifest: {
            permissions: [
                {
                    name: 'alexa::devices:all:notifications:write'
                }
            ],
            events: {
                publications: [
                    {
                        eventName: 'AMAZON.WeatherAlert.Activated'
                    },
                    {
                        eventName: 'AMAZON.SportsEvent.Updated'
                    },
                    {
                        eventName: 'AMAZON.MessageAlert.Activated'
                    },
                    {
                        eventName: 'AMAZON.OrderStatus.Updated'
                    },
                    {
                        eventName: 'AMAZON.Occasion.Updated'
                    },
                    {
                        eventName: 'AMAZON.TrashCollectionAlert.Activated'
                    },
                    {
                        eventName: 'AMAZON.MediaContent.Available'
                    },
                    {
                        eventName: 'AMAZON.SocialGameInvite.Available'
                    }
                ],
                endpoint: {
                    uri: '${JOVO_WEBHOOK_URL}' // Simply place your Jovo Webhook URL here
                },
            }
        }
    },
};

skills.json
{
“manifest”: {
“publishingInformation”: {
“locales”: {
“en-US”: {
“summary”: “Sample Short Description”,
“examplePhrases”: [
“Alexa open hello world”
],
“keywords”: [
“hello”,
“world”
],
“name”: “rxkeeper”,
“description”: “Sample Full Description”,
“smallIconUri”: “https://via.placeholder.com/108/09f/09f.png”,
“largeIconUri”: “https://via.placeholder.com/512/09f/09f.png
}
},
“isAvailableWorldwide”: true,
“testingInstructions”: “Sample Testing Instructions.”,
“category”: “EDUCATION_AND_REFERENCE”,
“distributionCountries”: []
},
“apis”: {
“custom”: {
“endpoint”: {
“uri”: “https://webhook.jovo.cloud/3d2574c3-4daa-4dc4-9ed4-9325288f0edd”,
“sslCertificateType”: “Wildcard”
},
“interfaces”: []
}
},
“manifestVersion”: “1.0”,
“privacyAndCompliance”: {
“allowsPurchases”: false,
“locales”: {
“en-US”: {
“privacyPolicyUrl”: “http://example.com/policy”,
“termsOfUseUrl”: “”
}
},
“isExportCompliant”: true,
“containsAds”: false,
“isChildDirected”: false,
“usesPersonalInfo”: false
},
“permissions”: [
{
“name”: “alexa::devices:all:notifications:write”
}
],
“events”: {
“publications”: [
{
“eventName”: “AMAZON.WeatherAlert.Activated”
},
{
“eventName”: “AMAZON.SportsEvent.Updated”
},
{
“eventName”: “AMAZON.MessageAlert.Activated”
},
{
“eventName”: “AMAZON.OrderStatus.Updated”
},
{
“eventName”: “AMAZON.Occasion.Updated”
},
{
“eventName”: “AMAZON.TrashCollectionAlert.Activated”
},
{
“eventName”: “AMAZON.MediaContent.Available”
},
{
“eventName”: “AMAZON.SocialGameInvite.Available”
}
],
“endpoint”: {
“sslCertificateType”: “Wildcard”,
“uri”: “https://webhook.jovo.cloud/3d2574c3-4daa-4dc4-9ed4-9325288f0edd
}
}
}
}

INTENT

async WeatherAlertIntent() {
    // Sets timestamp to current date and time
    let timestamp = new Date();
    timestamp = timestamp.toISOString();

    // Sets expiryTime 23 hours ahead of the current date and time
    let expiryTime = new Date();
    expiryTime.setHours(expiryTime.getHours() + 23);
    expiryTime = expiryTime.toISOString();

    const proactiveEventObject = {
        "timestamp": timestamp,
        "referenceId": "test-0001",
        "expiryTime": expiryTime,
        "event": {
            "name": "AMAZON.WeatherAlert.Activated",
            "payload": {
                "weatherAlert": {
                    "source": "localizedattribute:source",
                    "alertType": "TORNADO"
                }
            }
        },
        "localizedAttributes": [
            {
                "locale": "en-US",
                "source": "English Weather Channel"
            }
        ],
        "relevantAudience": {
            "type": "Multicast",
            "payload": {}
        }
    };
    const accessToken = await this.$alexaSkill.$proactiveEvent.getAccessToken(
          '',
          ''
      );
    console.log("AccessToken",accessToken)
    const result = await this.$alexaSkill.$proactiveEvent.sendProactiveEvent(proactiveEventObject, accessToken);
    console.log("RESULT",result)
},

Node js file for proactive events

const https = require('https');

async function sendRequest(postData) {

    return new Promise((resolve, reject) => {

        const opt = {

            hostname: 'webhook.jovo.cloud',

            path: '/3d2574c3-4daa-4dc4-9ed4-9325288f0edd',

            method: 'POST',

            headers: {

                'Content-Type': 'application/json',

                'Accept': 'application/json',

                'Content-Length': Buffer.byteLength(postData),

                'Accept-Charset': 'utf-8',

                'Signature': {

                    'SignatureCertChainUrl': 'https://s3.amazonaws.com/echo.api/echo-api-cert.pem'

                }

            },

        };

        const req = https.request(opt, (res) => {

            res.setEncoding('utf8');

            let rawData = '';

            res.on('data', (chunk) => {

                rawData += chunk;

            });

            res.on('end', () => {

                let parsedData;

                if (res.statusCode === 204) { // no content

                    return resolve(res.statusCode);

                }

                try {

                    if (rawData.length > 0) {

                        parsedData = JSON.parse(rawData);

                        return resolve(parsedData);

                    }

                } catch (e) {

                    return reject(JSON.parse(e));

                }

                resolve(res.statusCode);

            });

        }).on('error', (e) => {

            reject(e);

        });

        req.write(postData);

        req.end();

    });

}

let postData = {

    "version": "1.0",

    "session": {

        "new": true,

        "sessionId": "amzn1.echo-api.session.0000000-0000-0000-0000-00000000000",

        "application": {

            "applicationId": "amzn1.echo-sdk-ams.app.000000-d0ed-0000-ad00-000000d00ebe"

        },

        "attributes": {},

        "user": {

            "userId": "amzn1.account.AM3B00000000000000000000000"

        }

    },

    "context": {

        "System": {

            "application": {

                "applicationId": "amzn1.echo-sdk-ams.app.000000-d0ed-0000-ad00-000000d00ebe"

            },

            "user": {

                "userId": "amzn1.account.AM3B00000000000000000000000"

            },

            "device": {

                "deviceId": "amzn1.ask.device.XXXXXA6LX6BOBJF6XNWQM2ZO4NVVGZRFFEL6PMXKWLOHI36IY3B4XCSZKZPR42RAWCBSQEDNGS746OCC2PKR5KDIVAUY6F2DX5GV2SQAXPD7GMKQRWLG4LFKXFPVLVTXHFGLCQKHB7ZNBKLHQU4SJG6NNGA",

                "supportedInterfaces": {

                    "AudioPlayer": {}

                }

            },

            "apiEndpoint": "https://api.amazonalexa.com"

        },

        "AudioPlayer": {

            "offsetInMilliseconds": 0,

            "playerActivity": "IDLE"

        }

    },

    "request": {

        "type": "IntentRequest",

        "requestId": "amzn1.echo-api.request.0000000-0000-0000-0000-00000000000",

        "timestamp": "2019-04-30T12:02:56Z",

        "dialogState": "COMPLETED",

        "locale": "en-US",

        "intent": {

            "name": "WeatherAlertIntent",

            "confirmationStatus": "NONE",

            "slots": {}

        }

    }

}

postData = JSON.stringify(postData);

sendRequest(postData).then((result) => {

    console.log("///////////",result);

}, (reason) => {

    console.log("?????????????",reason);

});

after I run the node js file I get

 {
  version: '1.0',
  response: { shouldEndSession: true },
  sessionAttributes: {}
}

When I console the result I got the status 202 .can someone please help to find the issue.Thanks in advance


#2

I would recommend messaging your skill with the Messaging API (Setup explained here: Notification in alexa and google action)

async ON_REQUEST() {
        if ((this.$request as AlexaRequest).request?.type === 'Messaging.MessageReceived') {
               // Sets timestamp to current date and time
    let timestamp = new Date();
    timestamp = timestamp.toISOString();

    // Sets expiryTime 23 hours ahead of the current date and time
    let expiryTime = new Date();
    expiryTime.setHours(expiryTime.getHours() + 23);
    expiryTime = expiryTime.toISOString();

    const proactiveEventObject = {
        "timestamp": timestamp,
        "referenceId": "test-0001",
        "expiryTime": expiryTime,
        "event": {
            "name": "AMAZON.WeatherAlert.Activated",
            "payload": {
                "weatherAlert": {
                    "source": "localizedattribute:source",
                    "alertType": "TORNADO"
                }
            }
        },
        "localizedAttributes": [
            {
                "locale": "en-US",
                "source": "English Weather Channel"
            }
        ],
        "relevantAudience": {
            "type": "Multicast",
            "payload": {}
        }
    };
    const accessToken = await this.$alexaSkill.$proactiveEvent.getAccessToken(
          '',
          ''
      );
    console.log("AccessToken",accessToken)
    const result = await this.$alexaSkill.$proactiveEvent.sendProactiveEvent(proactiveEventObject, accessToken);
    console.log("RESULT",result)
            return;
        }
    },