我正在尝试在 alexa 中实现 SMS 和电子邮件服务,并使用 PHP、Jquery 来完成任务。我对这项技术非常陌生,在搜索了很多网站之后,我迷路了,无法开始。请让我知道有关该主题的任何参考。
问问题
377 次
3 回答
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
})
于 2017-04-05T03:24:25.440 回答
0
你可以使用与 alexa 配合得很好的 twilio https://github.com/krvarma/Amazon-Echo-and-Tw ilio在我看来,通过告诉 alexa 来从用户那里获得一封电子邮件是不可能的。Alexa 不会将您所说的所有内容转换为正确的文本,其他问题是特殊字符 - _ @
于 2017-03-29T22:31:08.767 回答
0
虽然亚马逊似乎已经有了一个答案,但如果您想要一个替代电子邮件,您可以使用https://www.sendgrid.com发送电子邮件,使用https://www.twilio.com发送短信、彩信、语音和更多的。Twilio 还拥有自己的转录和录音服务以及额外的可用模块,包括与 IBM watson 绑定。可能值得你看看。
于 2017-10-21T00:31:23.173 回答