meteor中节点whatsapi的集成

meteor中节点whatsapi的集成,meteor,npm,whatsapi,Meteor,Npm,Whatsapi,我想能够在流星中嗅到什么。我正在使用 最新稳定流星 节点whatsapi 阿鲁诺达的流星黑客:npm 并且可以了解过去的基本情况: 在meteor服务器启动时,我有: whatsapi = Meteor.npmRequire('whatsapi'); wa = whatsapi.createAdapter({ msisdn: '....', username: '....', password: '....', ccode: '....' }); wa.co

我想能够在流星中嗅到什么。我正在使用

  • 最新稳定流星
  • 节点whatsapi
  • 阿鲁诺达的流星黑客:npm
并且可以了解过去的基本情况:

在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);
});
我的问题是,当我尝试将store message.from或message.body添加到集合中时,meteor会给我“meteor代码必须始终在光纤中运行”错误)

帮助!

用于包装npm模块发出的任何回调。它会将回调包装成“光纤”,以便您可以在其中运行Meteor代码

例如:

wa.on('receivedMessage', Meteor.bindEnvironment(function(message) {
    console.log("From: " + message.from);
    console.log(message.body);
    Recipients.insert({msgfrom: message.from});
}));
它实际上是将回调中的代码放入光纤中

wa.on('receivedMessage', Meteor.bindEnvironment(function(message) {
    console.log("From: " + message.from);
    console.log(message.body);
    Recipients.insert({msgfrom: message.from});
}));