我想能在流星中嗅出什么东西。我在用
并能获得过去的基本知识:
在meteor服务器启动时,我有:
whatsapi = Meteor.npmRequire('whatsapi');
wa = whatsapi.createAdapter({
msisdn: '....',
username: '....',
password: '....',
ccode: '....'
});
wa.connect(function connected(err) {
if (err) {console.log(err); return;}
console.log('Connected');
wa.login(logged);
});
function logged(err) {
if (err) {console.log(err); return;}
console.log('Logged in');
wa.sendIsOnline();
};..。,它允许我通过方法调用发送和接收消息。
wa.sendMessage(recipient, content, function(err, id) {
if (err) {console.log(err.message); return;}
console.log('Server received message %s', id);
});下面的代码也可以工作,记录在控制台上接收到的消息。它位于服务器Meteor.startup中:
wa.on('receivedMessage', function(message) {
console.log("From: " + message.from);
console.log(message.body);
});我的问题是,当我试图将message.from或message.body存储到集合中时,meteor给出了"Meteor代码必须始终在光纤“内运行”错误“)
wa.on('receivedMessage', function(message) {
console.log("From: " + message.from);
console.log(message.body);
Recipients.insert({msgfrom: message.from});
});帮助!
发布于 2015-08-05 03:47:37
使用Meteor.bindEnvironment包装任何由npm模块发出的回调。它会将回调包装成一个“光纤”,这样您就可以在其中运行Meteor代码。
例如:
wa.on('receivedMessage', Meteor.bindEnvironment(function(message) {
console.log("From: " + message.from);
console.log(message.body);
Recipients.insert({msgfrom: message.from});
}));本质上,它所做的就是将回调中的代码放入一个光纤中。
https://stackoverflow.com/questions/31822273
复制相似问题