如何在alexa中实现短信和电子邮件服务?

时间:2017-03-15 09:36:14

标签: alexa alexa-skills-kit alexa-voice-service

我正在尝试在alexa中实现短信和电子邮件服务,并使用PHP,Jquery来完成任务。我对这项技术很陌生,在浏览了很多网站后,我迷失了方向,无法启动。请让我知道有关该主题的任何参考。

3 个答案:

答案 0 :(得分:2)

我建议使用Amazon SNS来完成这两项任务(短信和电子邮件)。您可以设置主题,为用户订阅,以及发送这些通知。最简单的前进方法是将Lambda用于您的Alexa Skill端点,如果您使用Nodejs,以下是如何执行此操作的示例:

'use strict';
var AWS = require("aws-sdk");

var playerSMS = (function () {
    var sns = new AWS.SNS();

return {
    sendTopicSubscribeRequest: function (phoneKey, callback) {
        var topicName = {
          Name: phoneKey.toString()
        };

        sns.createTopic(topicName, function(err, data) {
            if (err) {
                console.log(err, err.stack); // an error occurred
                callback('errorCreatingTopicARN'); 
            } else {
                console.log(JSON.stringify(data)); // successful response
                console.log('data.TopicArn = ' + data.TopicArn);
                var topicArn = data.TopicArn;
                console.log('topicArn = ' + topicArn);

                // now create the display name, which is a required attribute               
                var params = {
                  AttributeName: 'DisplayName',
                  TopicArn: topicArn, 
                  AttributeValue: 'My text'
                };                  
                sns.setTopicAttributes(params, function(err, data) {
                    if (err) {
                        console.log(err, err.stack); // an error occurred
                    } else {
                        console.log('data = ' + JSON.stringify(data) ); // successful response


                        // now subscribe the phone number to the topic                          
                        var subscribeInputParams = {
                          Protocol: 'sms', 
                          TopicArn: topicArn, 
                          Endpoint: '1-' + phoneKey.toString() //'1-425-890-8000'
                        };

                        sns.subscribe(subscribeInputParams, function(err, data) {
                            if (err) {
                                console.log(err, err.stack); // an error occurred
                            } else {
                                console.log(JSON.stringify(data)); // successful response
                            };
                            callback(topicArn); 
                        });                             
                    };
                });                                                                         
            };
        });         
    },


    publishSMS: function (incomingARN, incomingMessage, callback) {
        sns.publish({
            Message: incomingMessage,
            TopicArn: incomingARN
        }, function(err, data) {
            if (err) {
                console.log(err.stack);
                console.log(err, 'publishSMS function did not successfully complete.');
                var success = false;
            }

            if (data) {
                console.log('publishSMS function successfully sent a text to ' + incomingARN);
                var success = true;                 
            };

            // delay callback for 1 second to allow texts to arrive in order
            setTimeout(callBackAfterDelay, 200);

            function callBackAfterDelay() {
                callback(success);
            };      
        });
    }       
};      

})();
module.exports = playerSMS;

通过以下方式调用:

playerSMS.sendTopicSubscribeRequest(Player.phoneNumberGoesHere, function (topicArn) {
    if (!topicArn) {
        speechText = 'Hmm, there was a problem getting that set up. Please try again later.';               
    } else { // successfully created Topic ARN and sent the subscription request
        newLoadedPlayer.data.TopicARN = topicArn;
        speechText = 'You are now set up to receive texts when you ask for them. What would you like to do now?';
    };  
    Player.save(session, function () {
        response.ask(speechText, repromptTextToSay);    
    });         
}); 

playerSMS.publishSMS(ARNtoSend, textToSend, function (success) {
    // Do something here upon success or failure
})  

答案 1 :(得分:0)

你可以使用与alexa https://github.com/krvarma/Amazon-Echo-and-Twilio工作得很好的twilio。在我看来,通过告诉alexa来发送用户的电子邮件是不可能的。 Alexa并没有将您说的所有内容转换为正确的文本,其他问题是特殊字符 - _ @

答案 2 :(得分:0)

虽然似乎有一个已经使用亚马逊的答案,但如果你想要一个替代的电子邮件,你可以使用https://www.sendgrid.com进行电子邮件发送,https://www.twilio.com进行短信,彩信,语音等。 Twilio还拥有自己的转录和录制服务以及可用的额外模块,包括绑定到IBM watson。可能值得一看。

相关问题