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

How to implement SMS and Email service in alexa?

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

你可以使用 twilio,它与 alexa 配合得很好 https://github.com/krvarma/Amazon-Echo-and-Twilio 在我看来,通过告诉 alexa 从用户那里获取电子邮件是不可能的。 Alexa 不会将您所说的所有内容都转换为正确的文本,其他问题是特殊字符,如 - _ @

我建议使用 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
})  

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