1 | [![All dependencies](https://img.shields.io/librariesio/release/npm/rucaptcha-2captcha/2.2.0?style=flat-square "All dependencies of rucaptcha-2captcha@2.2.0")](https://libraries.io/npm/rucaptcha-2captcha/2.2.0)
|
2 | [![Reported vulnerabilities](https://img.shields.io/snyk/vulnerabilities/npm/rucaptcha-2captcha@2.2.0?style=flat-square "Reported vulnerabilities of rucaptcha-2captcha@2.2.0")](https://snyk.io/test/npm/rucaptcha-2captcha/2.2.0)
|
3 | [![Commits](https://flat.badgen.net/github/commits/ArthurKa/rucaptcha-2captcha)](https://github.com/ArthurKa/rucaptcha-2captcha/commits/master)
|
4 | [![NPM-version](https://img.shields.io/badge/npm-v2.2.0-blue.svg?style=flat-square&&logo=npm "Current NPM-version")](https://www.npmjs.com/package/rucaptcha-2captcha/v/2.2.0)
|
5 | [![Total downloads](https://img.shields.io/npm/dt/rucaptcha-2captcha?style=flat-square "Total downloads for all the time")](https://npm-stat.com/charts.html?package=rucaptcha-2captcha)
|
6 | [![Developed by](https://img.shields.io/badge/developed_by-ArthurKa-blueviolet.svg?style=flat-square "GitHub")](https://github.com/ArthurKa)\
|
7 | [![Publish size](https://flat.badgen.net/packagephobia/publish/rucaptcha-2captcha@2.2.0?label=publish 'Publish size of rucaptcha-2captcha@2.2.0')](https://packagephobia.now.sh/result?p=rucaptcha-2captcha@2.2.0)
|
8 | [![Install size](https://flat.badgen.net/packagephobia/install/rucaptcha-2captcha@2.2.0?label=install 'Install size of rucaptcha-2captcha@2.2.0')](https://packagephobia.now.sh/result?p=rucaptcha-2captcha@2.2.0)
|
9 | [![Minified size](https://img.shields.io/bundlephobia/min/rucaptcha-2captcha@2.2.0?style=flat-square&label=minified "Minified size of rucaptcha-2captcha@2.2.0")](https://bundlephobia.com/result?p=rucaptcha-2captcha@2.2.0)
|
10 | [![Minified + gzipped size](https://img.shields.io/bundlephobia/minzip/rucaptcha-2captcha@2.2.0?style=flat-square&label=minzipped "Minified + gzipped size of rucaptcha-2captcha@2.2.0")](https://bundlephobia.com/result?p=rucaptcha-2captcha@2.2.0)
|
11 |
|
12 | # rucaptcha-2captcha@2.2.0
|
13 |
|
14 | Helps you to operate with [RuCaptcha] or [2Captcha] services conveniently.
|
15 |
|
16 | Full documentation you can find on official sites: [RuCaptcha Docs][RuCaptchaAPI], [2Captcha Docs][2CaptchaAPI].
|
17 |
|
18 | ## Installation
|
19 | `rucaptcha-2captcha` is available via NPM:
|
20 | ```bash
|
21 | $ npm i rucaptcha-2captcha@2.2.0
|
22 | ```
|
23 |
|
24 | ## Usage
|
25 | ### Initialization
|
26 | #### Synopsis
|
27 |
|
28 | new RuCaptcha2Captcha(apiKey[, type]) → `captchaSolver` object
|
29 |
|
30 | | Name | Type | Required | Description
|
31 | |--------|--------------|----------|-
|
32 | | apiKey | string | yes | Your account API key from settings ([RuCaptcha][RuCaptchaSettings] \| [2Captcha][2CaptchaSettings]).
|
33 | | type | `2` \| `'2'` | no | Provide string or number **2** for [2Captcha].<br>Any other for [RuCaptcha].
|
34 |
|
35 | #### Example
|
36 | ```ts
|
37 | import RuCaptcha2Captcha from 'rucaptcha-2captcha';
|
38 |
|
39 | const captchaSolver = new RuCaptcha2Captcha(<YOUR_API_KEY>);
|
40 |
|
41 | // or for operating with 2Captcha.com
|
42 | const captchaSolver = new RuCaptcha2Captcha(<YOUR_API_KEY>, 2);
|
43 | ```
|
44 |
|
45 | ### captchaSolver.send method
|
46 | #### Synopsis
|
47 |
|
48 | captchaSolver.send(params) → `Promise<captcha_id>`
|
49 |
|
50 | | Name | Type | Required | Description
|
51 | |--------|--------|----------|-
|
52 | | params | object | yes | Object with properties from documentation ([RuCaptcha][RuCaptchaParams] \| [2Captcha][2CaptchaParams]),<br>except: `key`, `json` and `soft_id`.<br>Among these properties of `url`, `method`, `file` and `body`<br>can be used only the next combinations:<br> • single `url`<br> • `method` + `body`<br> • `method` + `file`
|
53 |
|
54 | Use this method to send captcha for solving.
|
55 |
|
56 | #### Example
|
57 | ```ts
|
58 | const id = await captchaSolver.send({
|
59 | method: 'base64',
|
60 | body: <base64_image_body>,
|
61 | // any other parameter from documentation,
|
62 | // except: file, key, json and soft_id
|
63 | });
|
64 |
|
65 | // id: '4503599627'
|
66 | ```
|
67 | #### Sending image from your local file system or the Internet
|
68 | ```ts
|
69 | const id = await captchaSolver.send({
|
70 | // url: './captchas/W68HP.gif',
|
71 | url: 'https://user-images.githubusercontent.com/16370704/87232185-aad0b680-c3c5-11ea-8cfc-b769bba631d4.gif',
|
72 | // any other parameter from documentation,
|
73 | // except: method, file, body, key, json and soft_id
|
74 | // for example
|
75 | regsense: 1, // for case-sensitive
|
76 | numeric: 4, // for both numbers and letters
|
77 | min_len: 5, //
|
78 | max_len: 5, // for exactly 5 symbols
|
79 | language: 2, // for Roman alphabet
|
80 | });
|
81 |
|
82 | // id: '4503599672'
|
83 | ```
|
84 |
|
85 | ### captchaSolver.get method
|
86 | #### Synopsis
|
87 |
|
88 | captchaSolver.get(id | ids | strIds) → `Promise<captcha_token>` | `Promise<Array<captcha_token>>`
|
89 |
|
90 | | Name | Type | Required | Description
|
91 | |--------|-----------|------------|-
|
92 | | id | string | one of all | Id of sent captcha via [send-method](#captchasolversend-method).
|
93 | | ids | Array<id> | one of all | Array of captcha ids.
|
94 | | strIds | string | one of all | String of comma-separated captcha ids.
|
95 |
|
96 | Method for getting captcha solutions.\
|
97 | Returns promise which resolves as soon as all captchas by provided ids will be solved on service.
|
98 |
|
99 | #### Example
|
100 | ```ts
|
101 | import { ArrayLikeString, isArrayLikeString } from 'rucaptcha-2captcha/src/types';
|
102 |
|
103 | const id = '<id1>';
|
104 | const id2 = '<id2>';
|
105 | const ids = '<id1>,<id2>';
|
106 |
|
107 | const token = await captchaSolver.get(id); // 'pgh3Ds'
|
108 | const tokens = await captchaSolver.get([id, id2]); // ['pgh3Ds', 'q5ZZpt']
|
109 | const tokens2 = await captchaSolver.get(ids as ArrayLikeString); // ['pgh3Ds', 'q5ZZpt']
|
110 | if(isArrayLikeString(ids)) {
|
111 | const tokens = await captchaSolver.get(ids); // ['pgh3Ds', 'q5ZZpt']
|
112 | }
|
113 | ```
|
114 |
|
115 | ### Solution reporting methods
|
116 | #### Synopsis
|
117 |
|
118 | captchaSolver.reportGood(id) → `Promise<Object>`\
|
119 | captchaSolver.reportBad(id) → `Promise<Object>`
|
120 |
|
121 | | Name | Type | Required | Description
|
122 | |------|--------|----------|-
|
123 | | id | string | yes | Id of sent captcha via [send-method](#captchasolversend-method).
|
124 |
|
125 | Use these methods for reporting captcha results.
|
126 |
|
127 | **Attention!** It's not necessary but better to send reports cause of refund of bad solutions and increasing solving accuracy by reporting good solutions.\
|
128 | Returns some info that was sent from server.
|
129 |
|
130 | #### Example
|
131 | ```ts
|
132 | const id = '<id1>';
|
133 | const result = await captchaSolver.reportGood(id);
|
134 | // or
|
135 | const result = await captchaSolver.reportBad(id);
|
136 |
|
137 | // result: { status: 1, request: 'OK_REPORT_RECORDED' }
|
138 | ```
|
139 |
|
140 | ### captchaSolver.solve method
|
141 | #### Synopsis
|
142 |
|
143 | captchaSolver.solve(params) → `Promise<Object { token, tokenIsGood, tokenIsBad }>`
|
144 |
|
145 | ##### Request
|
146 | | Name | Type | Required | Description
|
147 | |--------|--------|----------|-
|
148 | | params | object | yes | The same properties as for [captchaSolver.send](#captchasolversend-method) method.
|
149 |
|
150 | ##### Response
|
151 | | Name | Type | Description
|
152 | |-------------|----------|-
|
153 | | token | string | Solved captcha token.
|
154 | | tokenIsGood | function | Call it to report received token is correct.
|
155 | | tokenIsBad | function | Call it to report received token is wrong.
|
156 |
|
157 | captchaSolver.solve method is nothing more but convenient bundle of the next methods:
|
158 | - [captchaSolver.send](#captchasolversend-method)
|
159 | - [captchaSolver.get](#captchasolverget-method)
|
160 | - [captchaSolver.reportGood](#solution-reporting-methods)
|
161 | - [captchaSolver.reportBad](#solution-reporting-methods)
|
162 |
|
163 | You still can use them on your own.
|
164 |
|
165 | #### Example
|
166 | ```ts
|
167 | const { token, tokenIsGood, tokenIsBad } = await captchaSolver.solve({
|
168 | url: 'https://user-images.githubusercontent.com/16370704/87232185-aad0b680-c3c5-11ea-8cfc-b769bba631d4.gif',
|
169 | regsense: 1, // for case-sensitive
|
170 | numeric: 4, // for both numbers and letters
|
171 | min_len: 5,
|
172 | max_len: 5, // for exactly 5 symbols
|
173 | language: 2, // for Roman alphabet
|
174 | });
|
175 |
|
176 | if(token === 'W68HP') {
|
177 | console.log('Everything is just fine.');
|
178 | await tokenIsGood();
|
179 | } else {
|
180 | console.log('Captcha was solved incorrect:', token);
|
181 | await tokenIsBad();
|
182 | }
|
183 | ```
|
184 |
|
185 | ### captchaSolver.getWithPrice method
|
186 | #### Synopsis
|
187 |
|
188 | captchaSolver.getWithPrice(id) → `Promise<Object>`
|
189 |
|
190 | | Name | Type | Required | Description
|
191 | |------|--------|----------|-
|
192 | | id | string | yes | Id of sent captcha via [send-method](#captchasolversend-method).
|
193 |
|
194 | Use captchaSolver.getWithPrice method for getting captcha answer with its cost price.
|
195 |
|
196 | #### Example
|
197 | ```ts
|
198 | const info = await captchaSolver.getWithPrice(id);
|
199 | // info: { token: '6p6pck', price: '0.034' }
|
200 | ```
|
201 |
|
202 | ### captchaSolver.getBalance method
|
203 | #### Synopsis
|
204 |
|
205 | captchaSolver.getBalance() → `Promise<number>`
|
206 |
|
207 | Use for getting your account balance.\
|
208 | Note: don't use it too often because it decreases your API query limit.
|
209 |
|
210 | #### Example
|
211 | ```ts
|
212 | const balance = await captchaSolver.getBalance();
|
213 | // balance: 50.034
|
214 | ```
|
215 |
|
216 | ### captchaSolver.getPrices method
|
217 | #### Synopsis
|
218 |
|
219 | captchaSolver.getPrices() → `Promise<Object>`
|
220 |
|
221 | Use for getting actual service prices.\
|
222 | Note: this method does not decrease your API query limit.
|
223 |
|
224 | #### Example
|
225 | ```ts
|
226 | const prices = await captchaSolver.getPrices();
|
227 |
|
228 | // Warning! That is current actual prices. Prices and categories may change.
|
229 | /*
|
230 | prices in RUR for RuCaptcha service: {
|
231 | 'Обычная капча': 0.023,
|
232 | 'Текстовая капча': 0.023,
|
233 | 'ReCaptcha V2': 0.16,
|
234 | 'ReCaptcha V3': 0.16,
|
235 | GeeTest: 0.16,
|
236 | hCaptcha: 0.16,
|
237 | 'Capy Puzzle': 0.16,
|
238 | 'ReCaptcha V2 (старый метод)': 0.07,
|
239 | ClickCaptcha: 0.07,
|
240 | RotateCaptcha: 0.035,
|
241 | 'FunCaptcha с токеном': 0.16,
|
242 | KeyCaptcha: 0.16
|
243 | }
|
244 | prices in USD for 2Captcha service: {
|
245 | 'Normal Captcha': 0.00079,
|
246 | 'Text Captcha': 0.00079,
|
247 | 'ReCaptcha V2': 0.00299,
|
248 | 'ReCaptcha V3': 0.00299,
|
249 | GeeTest: 0.00299,
|
250 | 'ReCaptcha V2 (old method)': 0.0012,
|
251 | 'Solving ClickCaptcha': 0.0012,
|
252 | RotateCaptcha: 0.0005,
|
253 | FunCaptcha: 0.0005,
|
254 | 'FunCaptcha Token Method': 0.00299,
|
255 | KeyCaptcha: 0.00299,
|
256 | hCaptcha: 0.00299,
|
257 | Capy: 0.00299
|
258 | }
|
259 | */
|
260 | ```
|
261 |
|
262 | ---
|
263 |
|
264 | More info you can find in official documentation: [RuCaptcha Docs][RuCaptchaAPI], [2Captcha Docs][2CaptchaAPI].
|
265 |
|
266 | ## Testing
|
267 | Manually tested by the developer during development. Automated tests are not provided.
|
268 |
|
269 | ---
|
270 |
|
271 | Your improve suggestions and bug reports [are welcome](https://github.com/ArthurKa/rucaptcha-2captcha/issues) any time.
|
272 |
|
273 | [RuCaptcha]: https://rucaptcha.com
|
274 | [2Captcha]: https://2captcha.com
|
275 | [RuCaptchaAPI]: https://rucaptcha.com/api-rucaptcha
|
276 | [2CaptchaAPI]: https://2captcha.com/2captcha-api
|
277 | [RuCaptchaSettings]: https://rucaptcha.com/setting
|
278 | [2CaptchaSettings]: https://2captcha.com/setting
|
279 | [RuCaptchaParams]: https://rucaptcha.com/api-rucaptcha#normal_post
|
280 | [2CaptchaParams]: https://2captcha.com/2captcha-api#normal_post
|