从Node.js应用程序向Slack通道发送消息时出错

时间:2016-04-29 02:46:32

标签: node.js slack-api slack

尝试从Node.js app

发送消息

我使用了以下包https://github.com/xoxco/node-slack

详细参考完整源代码位于https://github.com/sudanvellakovilkanakavel/attendence-app

我无法理解

  1. 什么是hook_url

  2. 如何定义

  3. 错误输出

    CJBTDLDD0003:backend kanaks$ node readingFile.js
    /Users/kanaks/Desktop/backend/readingFile.js:2
    var slack = new Slack(hook_url,options);
                          ^
    
    ReferenceError: hook_url is not defined
        at Object.<anonymous> (/Users/kanaks/Desktop/backend/readingFile.js:2:23)
        at Module._compile (module.js:410:26)
        at Object.Module._extensions..js (module.js:417:10)
        at Module.load (module.js:344:32)
        at Function.Module._load (module.js:301:12)
        at Function.Module.runMain (module.js:442:10)
        at startup (node.js:136:18)
        at node.js:966:3
    

    我的代码

    var Slack = require('node-slack');
    var slack = new Slack(hook_url,options);
    
    //var slack = new Slack(hook_url,{proxy: http_proxy});
    
    //Trying to send message to slack from Node.js app
    //I have used following package https://github.com/xoxco/node-slack
    
    slack.send({
      text: 'Meassage from node.js app to slack!',
      channel: '#attendance',
      username: 'Bot'
    });
    
    var fs = require("fs");
    //reading the file
    fs.readFile('Attendance01-04-2016.dat','utf8',function (err,data){
      if (err) {
        return console.error(err);
      }
      //spliting each line
      var lines = data.split("\n");
      //storeing in array and printing the file
      for (i=0;i<=lines.length;)
      {
        console.log(lines[i]);
        i=i+1;
      }
    });
    

0 个答案:

没有答案