forked from eilvelia/tdl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
using-fluture.js
32 lines (24 loc) · 978 Bytes
/
using-fluture.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Fluture: https://github.com/fluture-js/Fluture
// This was written for fluture v8.0
const { Client } = require('tdl')
const { TDLib } = require('tdl-tdlib-addon')
const Future = require('fluture')
const client = new Client(new TDLib(), {
apiId: 2222, // Your api_id
apiHash: 'YOUR_API_HASH'
})
client.on('error', console.error)
// For TypeScript / Flow, `InvokeFuture` type for this function can be imported
// via `import type { InvokeFuture } from 'tdlib-types'`. Use it like this:
// `const invokeFuture = Future.encaseP(client.invoke) as InvokeFuture`
const invokeFuture = Future.encaseP(client.invoke)
const searchChat = username =>
invokeFuture({ _: 'searchPublicChat', username })
.map(chat => `Chat: ${chat.title}, id: ${chat.id}`)
.mapRej(err => `Error: ${err.message}`)
const login = Future.encaseP(client.login)
Future
.tryP(client.connect)
.chain(() => login())
.chain(() => searchChat('username'))
.fork(console.error, console.log)