ArthurKa/rucaptcha-2captcha

CAPTCHAFORUM

Administrator
Helps you to operate with RuCaptcha or 2Captcha services conveniently.

Full documentation you can find on official sites: RuCaptcha Docs, 2Captcha Docs.
Documentation https://githubmemory.com/repo/ArthurKa/rucaptcha-2captcha

Installation
rucaptcha-2captcha is available via NPM:
$ npm i rucaptcha-2captcha@2.2.0

Usage
Initialization
Synopsis
new RuCaptcha2Captcha(apiKey[, type]) → captchaSolver object
1633940732121.png

Example
Code:
import RuCaptcha2Captcha from 'rucaptcha-2captcha';

const captchaSolver = new RuCaptcha2Captcha(<YOUR_API_KEY>);

// or for operating with 2Captcha.com
const captchaSolver = new RuCaptcha2Captcha(<YOUR_API_KEY>, 2);

captchaSolver.send method
Synopsis
captchaSolver.send(params) → Promise<captcha_id>
1633940785604.png

Use this method to send captcha for solving.

Example
Code:
const id = await captchaSolver.send({
  method: 'base64',
  body: <base64_image_body>,
  // any other parameter from documentation,
  // except: file, key, json and soft_id
});

// id: '4503599627'

Sending image from your local file system or the Internet
Code:
const id = await captchaSolver.send({
  // url: './captchas/W68HP.gif',
  url: 'https://user-images.githubusercontent.com/16370704/87232185-aad0b680-c3c5-11ea-8cfc-b769bba631d4.gif',
  // any other parameter from documentation,
  // except: method, file, body, key, json and soft_id
  // for example
  regsense: 1,  // for case-sensitive
  numeric: 4,   // for both numbers and letters
  min_len: 5,   //
  max_len: 5,   // for exactly 5 symbols
  language: 2,  // for Roman alphabet
});

// id: '4503599672'

captchaSolver.get method
Synopsis
captchaSolver.get(id | ids | strIds) → Promise<captcha_token> | Promise<Array<captcha_token>>
1633940855590.png

Method for getting captcha solutions.
Returns promise which resolves as soon as all captchas by provided ids will be solved on service.

Example
Code:
import { ArrayLikeString, isArrayLikeString } from 'rucaptcha-2captcha/src/types';

const id = '<id1>';
const id2 = '<id2>';
const ids = '<id1>,<id2>';

const token = await captchaSolver.get(id); // 'pgh3Ds'
const tokens = await captchaSolver.get([id, id2]); // ['pgh3Ds', 'q5ZZpt']
const tokens2 = await captchaSolver.get(ids as ArrayLikeString); // ['pgh3Ds', 'q5ZZpt']
if(isArrayLikeString(ids)) {
  const tokens = await captchaSolver.get(ids); // ['pgh3Ds', 'q5ZZpt']
}

Solution reporting methods
Synopsis
captchaSolver.reportGood(id) → Promise<Object>
captchaSolver.reportBad(id) → Promise<Object>
1633940907834.png

Use these methods for reporting captcha results.

Attention! It's not necessary but better to send reports cause of refund of bad solutions and increasing solving accuracy by reporting good solutions.
Returns some info that was sent from server.

Example
Code:
const id = '<id1>';
const result = await captchaSolver.reportGood(id);
// or
const result = await captchaSolver.reportBad(id);

// result: { status: 1, request: 'OK_REPORT_RECORDED' }

captchaSolver.solve method
Synopsis
captchaSolver.solve(params) → Promise<Object { token, tokenIsGood, tokenIsBad }>

Request
1633940955202.png

Response
1633940974048.png

captchaSolver.solve method is nothing more but convenient bundle of the next methods:
You still can use them on your own.

Example
Code:
const { token, tokenIsGood, tokenIsBad } = await captchaSolver.solve({
  url: 'https://user-images.githubusercontent.com/16370704/87232185-aad0b680-c3c5-11ea-8cfc-b769bba631d4.gif',
  regsense: 1,  // for case-sensitive
  numeric: 4,   // for both numbers and letters
  min_len: 5,
  max_len: 5,   // for exactly 5 symbols
  language: 2,  // for Roman alphabet
});

if(token === 'W68HP') {
  console.log('Everything is just fine.');
  await tokenIsGood();
} else {
  console.log('Captcha was solved incorrect:', token);
  await tokenIsBad();
}