smart-chatbot
Advanced tools
Comparing version 0.0.4 to 0.0.5
39
main.js
const axios = require("axios"); | ||
const baseURL = "https://api.csycraft.xyz/chatbot"; | ||
const baseURL = "https://api.csycraft.xyz/chatbot?"; | ||
const version = require('./package.json').version; | ||
const packagename = require('./package.json').name; | ||
class Client { | ||
constructor(secret, botname) { | ||
constructor(secret, botname, logging = false) { | ||
if(logging == true) | ||
console.log(`[${packagename}] Enabling..`); | ||
this.chat = function(json) { | ||
return new Promise((resolve, reject) => { | ||
return new Promise(async(resolve, reject) => { | ||
if(!json.message || typeof json.message !== "string") reject("No message was provided"); | ||
if(!json.user || typeof json.user !== "number") json.user = 1; | ||
if(!json.language || typeof json.language !== "string" || (json.language != "tr" && json.language != "en")) json.language = "en"; | ||
axios.get(`${baseURL}?message=${encodeURIComponent(json.message)}&user=${encodeURIComponent(json.user)}&botname=${encodeURIComponent(botname)}`, { | ||
let getparams = { | ||
message: json.message, | ||
user: json.user, | ||
language: json.language | ||
}; | ||
let params = new URLSearchParams(getparams).toString(); | ||
axios.get(String(baseURL) + String(params), { | ||
headers: { | ||
'Authorization': `${secret}` | ||
'Authorization': `${secret}`, | ||
'Version': `${version}` | ||
} | ||
@@ -19,4 +35,7 @@ }).then(x => { | ||
} else { | ||
if(x && x.data && x.data.code && x.data.code == 203) { | ||
resolve("Please Enter Valid Secret Code.") | ||
if (x && x.data && x.data.code && x.data.code == 203) { | ||
resolve("Please Enter Valid Secret Code."); | ||
} else if (x && x.data && x.data.code && x.data.code == 205 && x.data.message) { | ||
console.error(x.data.message); | ||
resolve(x.data.message); | ||
} else { | ||
@@ -29,2 +48,5 @@ reject("No Api message was provided"); | ||
} | ||
if(logging == true) | ||
console.log(`[${packagename}] Enabled!`); | ||
} | ||
@@ -34,3 +56,4 @@ } | ||
module.exports = { | ||
Client: Client | ||
Client: Client, | ||
version: version | ||
} |
{ | ||
"name": "smart-chatbot", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Intelligent Chat Bot Api", | ||
@@ -18,6 +18,10 @@ "main": "main.js", | ||
"author": "bucksh0t", | ||
"license": "ISC", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/CsYBot/smart-chatbot/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/CsYBot/smart-chatbot.git" | ||
}, | ||
"homepage": "https://github.com/CsYBot/smart-chatbot/issues#readme", | ||
@@ -24,0 +28,0 @@ "dependencies": { |
@@ -0,5 +1,8 @@ | ||
<p align="center"><a href="https://nodei.co/npm/smart-chatbot"><img src="https://nodei.co/npm/smart-chatbot.png"></a></p> | ||
<p align="center"><img src="https://img.shields.io/npm/v/smart-chatbot?style=for-the-badge"> <img src="https://img.shields.io/github/repo-size/CsYBot/smart-chatbot?style=for-the-badge"> <img src="https://img.shields.io/npm/l/smart-chatbot?style=for-the-badge"> <img src="https://img.shields.io/npm/dt/smart-chatbot?style=for-the-badge"> <img src="https://img.shields.io/github/contributors/CsYBot/smart-chatbot?style=for-the-badge"> <img src="https://img.shields.io/github/package-json/dependency-version/CsYBot/smart-chatbot/axios?style=for-the-badge"> <a href="https://discord.gg/gkmwaAZQBu" target="_blank"> <img alt="Discord" src="https://img.shields.io/badge/CsYBot%20Support-Click%20here-7289d9?style=for-the-badge&logo=discord"> </a></p> | ||
# smart-chatbot | ||
<a href="https://npmjs.com/package/smart-chatbot" rel="nofollow"><img src="https://img.shields.io/npm/dt/smart-chatbot.svg?style=for-the-badge" alt="npm"></a><a href="https://npmjs.com/package/smart-chatbot" rel="nofollow"><img src="https://img.shields.io/npm/v/smart-chatbot.svg?style=for-the-badge" alt="npm"></a> | ||
**Examples:** | ||
**Javascript:** | ||
```js | ||
@@ -9,11 +12,8 @@ const chatbot = require("smart-chatbot"); | ||
(async() => { | ||
let reply = await chatclient.chat({ | ||
message: "Hello", | ||
user: "1" | ||
}); | ||
console.log(reply); | ||
}); | ||
chatclient.chat({ | ||
message: "Hello", | ||
user: "SECRET USER ID", | ||
language: "tr" // (tr, en) | ||
}).then(answer => console.log); | ||
``` | ||
<br> | ||
@@ -20,0 +20,0 @@ **What is SECRET KEY?** |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
16861
6
76
0