Skip to content

Commit e48633d

Browse files
committed
Add function for getting the underlying memcache
1 parent 74c224d commit e48633d

2 files changed

Lines changed: 123 additions & 93 deletions

File tree

DOCS.md

Lines changed: 109 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,25 @@
1515
- [Parameters][11]
1616
- [convertToFile][12]
1717
- [Parameters][13]
18-
- [credentialsObj][14]
19-
- [Properties][15]
20-
- [loginCallback][16]
21-
- [Parameters][17]
22-
- [apiObj][18]
23-
- [optionsObj][19]
24-
- [genericErrCb][20]
25-
- [Parameters][21]
26-
- [errDataCb][22]
27-
- [Parameters][23]
28-
- [searchAttribute][24]
29-
- [Parameters][25]
30-
- [monitoring][26]
31-
- [monitor][27]
32-
- [Parameters][28]
33-
- [cancelMonitoring][29]
34-
- [retryLoginCallback][30]
35-
- [Parameters][31]
18+
- [getMemCache][14]
19+
- [credentialsObj][15]
20+
- [Properties][16]
21+
- [loginCallback][17]
22+
- [Parameters][18]
23+
- [apiObj][19]
24+
- [optionsObj][20]
25+
- [genericErrCb][21]
26+
- [Parameters][22]
27+
- [errDataCb][23]
28+
- [Parameters][24]
29+
- [searchAttribute][25]
30+
- [Parameters][26]
31+
- [monitoring][27]
32+
- [monitor][28]
33+
- [Parameters][29]
34+
- [cancelMonitoring][30]
35+
- [retryLoginCallback][31]
36+
- [Parameters][32]
3637

3738
## login
3839

@@ -45,16 +46,16 @@ Encapsulates the login by caching the appstate in memory.
4546
### login
4647

4748
Call this to initialize the login module and log into Facebook using
48-
[facebook-chat-api][32].
49+
[facebook-chat-api][33].
4950
See examples/ for example usage.
5051

5152
#### Parameters
5253

53-
- `credentials` **[credentialsObj][33]**
54-
- `callback` **[loginCallback][34]** called after login completed (successfully or unsuccessfully)
55-
- `forceCreds` **[Boolean][35]** if true, forces a login with credentials even if
54+
- `credentials` **[credentialsObj][34]**
55+
- `callback` **[loginCallback][35]** called after login completed (successfully or unsuccessfully)
56+
- `forceCreds` **[Boolean][36]** if true, forces a login with credentials even if
5657
appstate exists (optional, default `false`)
57-
- `options` **[optionsObj][36]** any options you wish to pass to the API on login;
58+
- `options` **[optionsObj][37]** any options you wish to pass to the API on login;
5859
by default, sets `logLevel` to `error` and `forceLogin` to `true` (auto-approves errors asking
5960
for approval of recent logins for simplicity) (optional, default `defaultOptions`)
6061

@@ -64,26 +65,26 @@ Dumps the current login into a specified file.
6465

6566
#### Parameters
6667

67-
- `filename` **[string][37]** Name of the file specifying where to store the login
68-
- `callback` **[genericErrCb][38]** Callback to use after writing the file
68+
- `filename` **[string][38]** Name of the file specifying where to store the login
69+
- `callback` **[genericErrCb][39]** Callback to use after writing the file
6970

7071
### loadLogin
7172

7273
Reads a new login into memory from a file.
7374

7475
#### Parameters
7576

76-
- `filename` **[string][37]** Name of the file specifying where the imported login
77+
- `filename` **[string][38]** Name of the file specifying where the imported login
7778
is stored
78-
- `callback` **[genericErrCb][38]** Callback to use after reading the login
79+
- `callback` **[genericErrCb][39]** Callback to use after reading the login
7980

8081
### logout
8182

8283
Logs out of Facebook.
8384

8485
#### Parameters
8586

86-
- `callback` **[errDataCb][39]**
87+
- `callback` **[errDataCb][40]**
8788

8889
### convert
8990

@@ -93,9 +94,9 @@ an fbchat bot with BotCore.
9394

9495
#### Parameters
9596

96-
- `filename` **[string][37]** Name of the file whose location contains the
97+
- `filename` **[string][38]** Name of the file whose location contains the
9798
appstate data to be converted
98-
- `callback` **[errDataCb][39]** Callback to use after conversion completed,
99+
- `callback` **[errDataCb][40]** Callback to use after conversion completed,
99100
passed the converted session
100101

101102
### convertToFile
@@ -104,9 +105,20 @@ A variant of `convert` that directly outputs the converted session to a file.
104105

105106
#### Parameters
106107

107-
- `appstate` **[string][37]** Location of appstate to be converted
108-
- `output` **[string][37]** Where to place the converted session
109-
- `callback` **[genericErrCb][38]** Callback called after conversion
108+
- `appstate` **[string][38]** Location of appstate to be converted
109+
- `output` **[string][38]** Where to place the converted session
110+
- `callback` **[genericErrCb][39]** Callback called after conversion
111+
112+
### getMemCache
113+
114+
Exposes the underlying memjs memcache instance, which can be used for
115+
temporary storage. Use wisely, or you may break your BotCore installation!
116+
117+
> NOTE: if you call this before logging in with [login][1],
118+
> it will return nothing; the memcache is not initialized until you log in.
119+
120+
Returns **[Object][41]** The underlying BotCore [memjs][42]
121+
instance
110122

111123
## credentialsObj
112124

@@ -117,7 +129,7 @@ of several required keys that allow BotCore to log in to both Facebook and the M
117129
(used to cache logins) on your behalf. The keys are listed and explained below.
118130

119131
> **NOTE**: to obtain the values for the `MEMCACHIER_` variables, you must [sign up for a free
120-
> MemCachier account][40] and create a cache. From there, you
132+
> MemCachier account][43] and create a cache. From there, you
121133
> will be able to retrieve the requisite info from your dashboard.
122134
123135
I recommend the following two methods for storing your credentials object due to their ease of use:
@@ -151,53 +163,53 @@ Type: [Object][41]
151163

152164
### Properties
153165

154-
- `MEMCACHIER_USERNAME` **[string][37]** Memcachier username (from dashboard) for storage
155-
- `MEMCACHIER_PASSWORD` **[string][37]** Memcachier password (from dashboard) for storage
156-
- `MEMCACHIER_SERVERS` **[string][37]** Memcachier servers (from dashboard) for storage
157-
- `FACEBOOK_EMAIL` **[string][37]** Facebook account email for login (optional if already logged in once)
158-
- `FACEBOOK_PASSWORD` **[string][37]** Facebook account password for login (optional if already logged in once)
166+
- `MEMCACHIER_USERNAME` **[string][38]** Memcachier username (from dashboard) for storage
167+
- `MEMCACHIER_PASSWORD` **[string][38]** Memcachier password (from dashboard) for storage
168+
- `MEMCACHIER_SERVERS` **[string][38]** Memcachier servers (from dashboard) for storage
169+
- `FACEBOOK_EMAIL` **[string][38]** Facebook account email for login (optional if already logged in once)
170+
- `FACEBOOK_PASSWORD` **[string][38]** Facebook account password for login (optional if already logged in once)
159171

160172
## loginCallback
161173

162-
Type: [Function][42]
174+
Type: [Function][44]
163175

164176
### Parameters
165177

166-
- `err` **[string][37]** indicates errors (null if login is successful)
167-
- `api` **[apiObj][43]** null if login fails, see
168-
[facebook-chat-api][32] for details
178+
- `err` **[string][38]** indicates errors (null if login is successful)
179+
- `api` **[apiObj][45]** null if login fails, see
180+
[facebook-chat-api][33] for details
169181

170182
## apiObj
171183

172184
An API instance of the facebook-chat-api (see
173-
[here][32] for details)
185+
[here][33] for details)
174186

175187
Type: [Object][41]
176188

177189
## optionsObj
178190

179191
An object containing options to be passed to the underlying
180192
facebook-chat-api instance on login (see
181-
[here][44]
193+
[here][46]
182194
for details)
183195

184196
Type: [Object][41]
185197

186198
## genericErrCb
187199

188-
Type: [Function][42]
200+
Type: [Function][44]
189201

190202
### Parameters
191203

192-
- `err` **[string][37]** Message specifying the error (or null if none)
204+
- `err` **[string][38]** Message specifying the error (or null if none)
193205

194206
## errDataCb
195207

196-
Type: [Function][42]
208+
Type: [Function][44]
197209

198210
### Parameters
199211

200-
- `err` **[string][37]** Message specifying the error (or null if none)
212+
- `err` **[string][38]** Message specifying the error (or null if none)
201213
- `success` **[Object][41]** Data returned from the successful operation
202214

203215
## searchAttribute
@@ -211,9 +223,9 @@ the other information.
211223
### Parameters
212224

213225
- `data` **[Object][41]** facebook-chat-api appstate
214-
- `key` **[string][37]** The key to locate
226+
- `key` **[string][38]** The key to locate
215227

216-
Returns **[string][37]** The value of the key (or null if not found)
228+
Returns **[string][38]** The value of the key (or null if not found)
217229

218230
## monitoring
219231

@@ -230,15 +242,15 @@ Begins monitoring a specified API instance.
230242

231243
#### Parameters
232244

233-
- `apiInstance` **[apiObj][43]** An instance of the facebook-chat-api to monitor
234-
- `maintainerId` **[string][37]** User ID of the maintainer to notify on failures
235-
- `botName` **[string][37]** Name of the bot running
236-
- `credentialsObj` **[credentialsObj][33]** Object containing the user credentials
237-
- `botProcessRef` **[process][45]** Node.js process to monitor (optional)
238-
- `retryLoginCallback` **[retryLoginCallback][46]** A callback to send a new API
245+
- `apiInstance` **[apiObj][45]** An instance of the facebook-chat-api to monitor
246+
- `maintainerId` **[string][38]** User ID of the maintainer to notify on failures
247+
- `botName` **[string][38]** Name of the bot running
248+
- `credentialsObj` **[credentialsObj][34]** Object containing the user credentials
249+
- `botProcessRef` **[process][47]** Node.js process to monitor (optional)
250+
- `retryLoginCallback` **[retryLoginCallback][48]** A callback to send a new API
239251
instance to if login failed and a re-attempted login succeeded (optional –
240252
omitting this callback is equivalent to disabling the retry login feature)
241-
- `pingIntervalInMinutes` **[number][47]** The number of minutes between
253+
- `pingIntervalInMinutes` **[number][49]** The number of minutes between
242254
checks that the bot is still running (optional, default `10`)
243255

244256
### cancelMonitoring
@@ -247,11 +259,11 @@ Cancels the monitoring of the current bot process.
247259

248260
## retryLoginCallback
249261

250-
Type: [Function][42]
262+
Type: [Function][44]
251263

252264
### Parameters
253265

254-
- `api` **[apiObj][43]** A new instance of the facebook-chat-api after a successful login
266+
- `api` **[apiObj][45]** A new instance of the facebook-chat-api after a successful login
255267

256268
[1]: #login
257269

@@ -279,70 +291,74 @@ Type: [Function][42]
279291

280292
[13]: #parameters-5
281293

282-
[14]: #credentialsobj
294+
[14]: #getmemcache
283295

284-
[15]: #properties
296+
[15]: #credentialsobj
285297

286-
[16]: #logincallback
298+
[16]: #properties
287299

288-
[17]: #parameters-6
300+
[17]: #logincallback
289301

290-
[18]: #apiobj
302+
[18]: #parameters-6
291303

292-
[19]: #optionsobj
304+
[19]: #apiobj
293305

294-
[20]: #genericerrcb
306+
[20]: #optionsobj
295307

296-
[21]: #parameters-7
308+
[21]: #genericerrcb
297309

298-
[22]: #errdatacb
310+
[22]: #parameters-7
299311

300-
[23]: #parameters-8
312+
[23]: #errdatacb
301313

302-
[24]: #searchattribute
314+
[24]: #parameters-8
303315

304-
[25]: #parameters-9
316+
[25]: #searchattribute
305317

306-
[26]: #monitoring
318+
[26]: #parameters-9
307319

308-
[27]: #monitor
320+
[27]: #monitoring
309321

310-
[28]: #parameters-10
322+
[28]: #monitor
311323

312-
[29]: #cancelmonitoring
324+
[29]: #parameters-10
313325

314-
[30]: #retrylogincallback
326+
[30]: #cancelmonitoring
315327

316-
[31]: #parameters-11
328+
[31]: #retrylogincallback
317329

318-
[32]: https://github.com/Schmavery/facebook-chat-api
330+
[32]: #parameters-11
319331

320-
[33]: #credentialsobj
332+
[33]: https://github.com/Schmavery/facebook-chat-api
321333

322-
[34]: #logincallback
334+
[34]: #credentialsobj
323335

324-
[35]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
336+
[35]: #logincallback
325337

326-
[36]: #optionsobj
338+
[36]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
327339

328-
[37]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
340+
[37]: #optionsobj
329341

330-
[38]: #genericerrcb
342+
[38]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
331343

332-
[39]: #errdatacb
344+
[39]: #genericerrcb
333345

334-
[40]: https://www.memcachier.com/users/signup
346+
[40]: #errdatacb
335347

336348
[41]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
337349

338-
[42]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
350+
[42]: https://memjs.netlify.app
351+
352+
[43]: https://www.memcachier.com/users/signup
353+
354+
[44]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
339355

340-
[43]: #apiobj
356+
[45]: #apiobj
341357

342-
[44]: https://github.com/Schmavery/facebook-chat-api/blob/master/DOCS.md#apisetoptionsoptions
358+
[46]: https://github.com/Schmavery/facebook-chat-api/blob/master/DOCS.md#apisetoptionsoptions
343359

344-
[45]: https://nodejs.org/api/process.html
360+
[47]: https://nodejs.org/api/process.html
345361

346-
[46]: #retrylogincallback
362+
[48]: #retrylogincallback
347363

348-
[47]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
364+
[49]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number

src/login.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,20 @@ exports.convertToFile = (appstate, output, callback) => {
256256
});
257257
}
258258

259+
/**
260+
* Exposes the underlying memjs memcache instance, which can be used for
261+
* temporary storage. Use wisely, or you may break your BotCore installation!
262+
*
263+
* > NOTE: if you call this before logging in with {@link login},
264+
* it will return nothing; the memcache is not initialized until you log in.
265+
*
266+
* @returns {Object} The underlying BotCore [memjs](https://memjs.netlify.app)
267+
* instance
268+
*/
269+
exports.getMemCache = () => {
270+
return mem;
271+
}
272+
259273
/**
260274
* facebook-chat-api appstates are an array of objects containing "key" and
261275
* "value" keys and additional properties (that the Python API doesn't use).

0 commit comments

Comments
 (0)