Registry / gaming / cw-rest-api

cw-rest-api

JSON →
library1.8.0jsnpmunverified

cw-rest-api is a Node.js wrapper and HTTP REST API server for the ChatWars MMORPG Telegram game. Version 1.8.0 provides a promise-based interface to interact with the ChatWars API, including user profile retrieval, stock information, and trade commands (buy/sell). It uses AMQP for messaging with automatic reconnection via node-amqp-connection-manager. The package requires Node.js >=8.11.3 and is designed for building Telegram bots or other applications that automate gameplay. Key differentiators: provides both a programmatic Node.js API and a standalone HTTP server, supports authentication flow via Telegram, and offers real-time trade capabilities. Release cadence appears to be sporadic, with last update in 2018.

npm install cw-rest-api
INSTALL
IMPORT
SIG · CW-REST-API
C
cw-rest-api
gamingjavascriptv1.8.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CWExchange
import CWExchange from 'cw-rest-api';
import { CWExchange } from 'cw-rest-api';
CWExchange is the default export. Using named import will cause undefined error.
CWExchange
const CWExchange = require('cw-rest-api').default;
const { CWExchange } = require('cw-rest-api');
CommonJS require must use .default to access the default export.
CWExchange
import CWExchange from 'cw-rest-api';
ES6 import is the recommended way. The package provides ESM support.

Shows how to import CWExchange, connect, and make API calls (profile, stock, trade) with token authentication.

import CWExchange from 'cw-rest-api'; const cw = new CWExchange(); const manager = cw.connect(); manager.on('connect', async () => { try { const profile = await cw.requestProfile(12345, 'my-token-abc'); console.log(profile); const stock = await cw.requestStock(12345, 'my-token-abc'); console.log(stock); cw.wantToBuy( 12345, { itemCode: '07', quantity: 12, price: 1 }, 'my-token-abc' ).then(deal => console.log(deal)) .catch(err => console.error(err)); } catch (e) { console.error(e); } });
Debug
Known issues
deprecatedPackage cw-rest-api has not been updated since 2018 and the underlying ChatWars game API may have changed. Use at your own risk.
fix
Consider using a maintained alternative or fork. Check game API compatibility before using.
affects: all
breakingNode.js version 8.11.3 is required (as per engines field). Using newer Node.js versions may cause unexpected issues.
fix
Use Node.js version 8.11.3 or use nvm to switch versions.
affects: <8.11.3
gotchaImporting as named export (e.g., { CWExchange }) results in undefined because it is a default export.
fix
Use default import: import CWExchange from 'cw-rest-api'; or require('cw-rest-api').default.
affects: all
breakingEnvironment variables CW_APP_NAME and CW_APP_PASSWORD must be set for the HTTP server to start.
fix
Set environment variables: export CW_APP_NAME=your_username; export CW_APP_PASSWORD=your_password.
affects: all
deprecatedThe REST API HTTP server is provided but no longer maintained. Security vulnerabilities may exist.
fix
If using the server, ensure proper network isolation and update dependencies manually.
affects: all
Errors
Common errors & fixes
TypeError: CWExchange is not a constructor
Using named import instead of default import: import { CWExchange } from 'cw-rest-api'.
fix
Use default import: import CWExchange from 'cw-rest-api';
Error: connect ECONNREFUSED
AMQP server (e.g., RabbitMQ) is not running or connection parameters are incorrect.
fix
Start the AMQP server or check apiUrl and accessToken passed to cw.connect().
Error: Invalid credentials
The provided token is invalid or expired for the given userId.
fix
Re-authenticate via the API/auth endpoint to obtain a new token.
Upgrade
Version history
1.8.0latest on npm
Audit
Dependencies
node-amqp-connection-managerrequiredUsed for AMQP connection management with automatic reconnection.
Agent activity
39 hits · last 30 days
node
36
Resources
cw-rest-api — npm install cw-rest-api · libregistry