gpt4 book ai didi

javascript - 类型错误:mitsukuApi.send 不是函数

转载 作者:行者123 更新时间:2023-11-30 07:31:20 25 4
gpt4 key购买 nike

<分区>

我尝试使用 mitsuku chatbot's API并测试以下内容。

var m = require("mitsuku-api")

m.send('hello world')
.then(function(response){
console.log(response);
});

我正在使用 ubuntu 控制台并安装了 nodejs 和 npm。但是当我尝试运行上面的代码时遇到以下错误。

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

TypeError: mitsukuApi.send is not a function at Object. (/home/manuelanayantarajeyaraj/node_modules/mitsuku-api/mitsukutest.js:3:12)
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

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);
};

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com