TypeError:mitsukuApi.send不是函数

Nay*_*raj 1 javascript api function typeerror node.js

我尝试使用mitsuku chatbot的API并测试以下内容.

var m = require("mitsuku-api")

m.send('hello world')
  .then(function(response){
    console.log(response);
  });
Run Code Online (Sandbox Code Playgroud)

我正在使用ubuntu控制台并安装了nodejs和npm.但是当我尝试运行上述操作时,我面临以下错误.

/home/manuelanayantarajeyaraj/node_modules/mitsuku-api/mitsukutest.js:3 mitsukuApi.send('hello world')^

TypeError:mitsukuApi.send不是Object的函数.(/home/manuelanayantjeyayaj/node_modules/mitsuku-api/mitsukutest.js:3:12)
在Module._compile(module.js:410:26)
的Object.Module._extensions..js(module.js:417:10) ) 启动时 在Function.Module.runMain(module.js:442:10)的 Function.Module._load(module.js:301:12)的
Module.load(module.js:344:32)
处(node.js) :136:18) 在node.js:966:3


mitsuku.js文件

'use strict';

var Promise = require('bluebird'),
    cheerio = require('cheerio'),
    superagent = require('superagent');

var ENDPOINT_CHAT_MITSUKU = 'https://kakko.pandorabots.com/pandora/talk?botid=87437a824e345a0d&skin=chat',
    MESSAGE_REGEX = /(Mitsuku -(.*))/,
    MESSAGE_REJECT_REGEX = /(x(.*)x[^\s]+)|(\|)|(BYESPLIT X1234)/ig,
    MESSAGE_SENDER_TAG = 'You -';

function getRawHtmlForMessage(mitsuku, message) {
    return new Promise(function (resolve, reject) {
        if (!mitsuku) {
            return reject(new Error('Mitsuku cannot be null'));
        }
        if (!message) {
            return reject(new Error('Message cannot be null or empty'));
        }

        var agent = mitsuku._agent,
            endpoint = mitsuku._endpoint,
            req;

        req = agent.post(endpoint);
        agent.attachCookies(req);
        req.set('Content-Type', 'application/x-www-form-urlencoded')
            .send({ message: message })
            .end(function (err, res) {
                if (err) {
                    return reject(err);
                }
                agent.saveCookies(res);
                resolve(res.text);
            });
    });
}

function parseMessageFromHtml(html) {
    var conv = cheerio.load(html)('body')
        .find('p')
        .text()
        .trim();

    var match = MESSAGE_REGEX.exec(conv),
        message,
        prevMessageStart;

    if (match && match.length > 0) {
        message = match[match.length - 1];
        prevMessageStart = message.indexOf(MESSAGE_SENDER_TAG);
        if (prevMessageStart != -1) {
            message = message.substr(0, prevMessageStart);
        }
        return message.replace(MESSAGE_REJECT_REGEX, '').trim();
    } else {
        throw new Error("Could not parse Mitsuku response");
    }
}

/**
 * Create new Mitsuku API for the given options.
 *
 * @param options
 * @constructor
 */
function Mitsuku(options) {
    options = options || {};
    this._tag = options.tag || 'Anonymous';
    this._agent = superagent.agent();
    this._endpoint = options.endpoint || ENDPOINT_CHAT_MITSUKU;
}

/**
 * Send a message to this {@link Mitsuku} instance.
 *
 * @param message
 * @return bluebird message response promise
 */
Mitsuku.prototype.send = function(message) {
    return getRawHtmlForMessage(this, message)
        .then(parseMessageFromHtml)
};

/**
 * Get the tag this {@link Mitsuku} was setup with.
 *
 * @returns {*|string}
 */
Mitsuku.prototype.getTag = function() {
    return '' + this._tag;
};

/**
 * Describe this {@link Mitsuku} instance.
 *
 * @returns {*|string}
 */
Mitsuku.prototype.toString = function() {
    return this.getTag();
};

/**
 * Mitsuku API module
 * @module lib/mitsuku
 */

/**
 * Create new instance of {@link Mitsuku} for the given options.
 *
 * @param options
 * @returns {Mitsuku}
 */
module.exports = function newInstance(options) {
    return new Mitsuku(options);
};
Run Code Online (Sandbox Code Playgroud)

在这方面的任何帮助将不胜感激.

小智 5

我是Mitsuku的开发人员,阻止了你的代码工作.如果不首先询问他人的工作,那就嘲笑其他人的工作并不好.

我原以为我们放在Github存储库上的"停止和停止"通知就足以说明这一点:https://github.com/eleventigers/mitsuku-api/issues/11

如果您想在工作中使用Mitsuku,请通过info@pandorabots.com与我联系,我们可以讨论定价.