@grammy-x/conversations 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/question-helper.ts +126 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grammy-x/conversations",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"access": "restricted"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@grammy-x/core": "0.1.
|
|
12
|
+
"@grammy-x/core": "0.1.3"
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
15
|
"grammy": "^1.24.0",
|
package/src/question-helper.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import type { Conversation } from "@grammyjs/conversations"
|
|
2
2
|
import { CallbackQueryContext, Context, InlineKeyboard, Keyboard } from "grammy"
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
ChatAdministratorRights,
|
|
5
|
+
ChatShared,
|
|
6
|
+
Contact,
|
|
7
|
+
Location,
|
|
8
|
+
Poll,
|
|
9
|
+
UsersShared,
|
|
10
|
+
} from "grammy/types"
|
|
4
11
|
import { smartReply } from "@grammy-x/core"
|
|
5
12
|
|
|
6
13
|
type MaybePromise<T> = PromiseLike<T> | T
|
|
@@ -37,10 +44,46 @@ interface QuestionChatParameters extends QuestionParameters {
|
|
|
37
44
|
requiredBotRights?: ChatAdministratorRights
|
|
38
45
|
botIsMember?: boolean
|
|
39
46
|
isChannel: boolean
|
|
47
|
+
requestTitle?: boolean
|
|
48
|
+
requestUsername?: boolean
|
|
49
|
+
requestPhoto?: boolean
|
|
40
50
|
}
|
|
41
51
|
}
|
|
42
52
|
|
|
43
|
-
|
|
53
|
+
interface QuestionUserParameters extends QuestionParameters {
|
|
54
|
+
user?: {
|
|
55
|
+
isBot?: boolean
|
|
56
|
+
isPremium?: boolean
|
|
57
|
+
requestName?: boolean
|
|
58
|
+
requestUsername?: boolean
|
|
59
|
+
requestPhoto?: boolean
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface QuestionUsersParameters extends QuestionParameters {
|
|
64
|
+
users?: {
|
|
65
|
+
maxQuantity?: number
|
|
66
|
+
isBot?: boolean
|
|
67
|
+
isPremium?: boolean
|
|
68
|
+
requestName?: boolean
|
|
69
|
+
requestUsername?: boolean
|
|
70
|
+
requestPhoto?: boolean
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface QuestionPollParameters extends QuestionParameters {
|
|
75
|
+
poll?: {
|
|
76
|
+
type?: "regular" | "quiz"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
type QuestionUniversalParameters = Partial<
|
|
81
|
+
QuestionMultiParameters &
|
|
82
|
+
QuestionChatParameters &
|
|
83
|
+
QuestionUserParameters &
|
|
84
|
+
QuestionUsersParameters &
|
|
85
|
+
QuestionPollParameters
|
|
86
|
+
>
|
|
44
87
|
|
|
45
88
|
interface QuestionInternalParameters extends QuestionUniversalParameters {
|
|
46
89
|
continueButton?: string
|
|
@@ -185,7 +228,9 @@ export class QuestionHelper<
|
|
|
185
228
|
chat_is_channel: chat.isChannel,
|
|
186
229
|
bot_administrator_rights: chat.requiredBotRights,
|
|
187
230
|
bot_is_member: chat.botIsMember,
|
|
188
|
-
|
|
231
|
+
request_photo: chat.requestPhoto,
|
|
232
|
+
request_title: chat.requestTitle,
|
|
233
|
+
request_username: chat.requestUsername ?? true,
|
|
189
234
|
user_administrator_rights: chat.requiredUserRights,
|
|
190
235
|
})
|
|
191
236
|
.oneTime(true)
|
|
@@ -199,6 +244,84 @@ export class QuestionHelper<
|
|
|
199
244
|
return answer.msg.chat_shared as ChatShared
|
|
200
245
|
}
|
|
201
246
|
|
|
247
|
+
user = async (text: string, options?: QuestionUserParameters) => {
|
|
248
|
+
const user = options?.user
|
|
249
|
+
const markup = new Keyboard()
|
|
250
|
+
.requestUsers("Выбрать пользователя 🔍", randomInteger(0, 999999), {
|
|
251
|
+
max_quantity: 1,
|
|
252
|
+
request_name: user?.requestName,
|
|
253
|
+
request_photo: user?.requestPhoto,
|
|
254
|
+
request_username: user?.requestUsername ?? true,
|
|
255
|
+
user_is_bot: user?.isBot,
|
|
256
|
+
user_is_premium: user?.isPremium,
|
|
257
|
+
})
|
|
258
|
+
.oneTime(true)
|
|
259
|
+
.resized(true)
|
|
260
|
+
const message = await this.reply(text, { ...options, markup })
|
|
261
|
+
const answer = await this.conversation.waitFor(":users_shared")
|
|
262
|
+
|
|
263
|
+
this.updateCtx(answer)
|
|
264
|
+
|
|
265
|
+
await (answer?.msg as any)?.delete?.().catch?.(() => {})
|
|
266
|
+
return answer.msg.users_shared?.users[0] as UsersShared["users"][number]
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
users = async (text: string, options?: QuestionUsersParameters) => {
|
|
270
|
+
const users = options?.users
|
|
271
|
+
const markup = new Keyboard()
|
|
272
|
+
.requestUsers("Выбрать пользователей 🔍", randomInteger(0, 999999), {
|
|
273
|
+
max_quantity: users?.maxQuantity,
|
|
274
|
+
request_name: users?.requestName,
|
|
275
|
+
request_photo: users?.requestPhoto,
|
|
276
|
+
request_username: users?.requestUsername ?? true,
|
|
277
|
+
user_is_bot: users?.isBot,
|
|
278
|
+
user_is_premium: users?.isPremium,
|
|
279
|
+
})
|
|
280
|
+
.oneTime(true)
|
|
281
|
+
.resized(true)
|
|
282
|
+
const message = await this.reply(text, { ...options, markup })
|
|
283
|
+
const answer = await this.conversation.waitFor(":users_shared")
|
|
284
|
+
|
|
285
|
+
this.updateCtx(answer)
|
|
286
|
+
|
|
287
|
+
await (answer?.msg as any)?.delete?.().catch?.(() => {})
|
|
288
|
+
return answer.msg.users_shared as UsersShared
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
contact = async (text: string, options?: QuestionParameters) => {
|
|
292
|
+
const markup = new Keyboard().requestContact("Поделиться контактом 📞").oneTime(true).resized(true)
|
|
293
|
+
const message = await this.reply(text, { ...options, markup })
|
|
294
|
+
const answer = await this.conversation.waitFor(":contact")
|
|
295
|
+
|
|
296
|
+
this.updateCtx(answer)
|
|
297
|
+
|
|
298
|
+
await (answer?.msg as any)?.delete?.().catch?.(() => {})
|
|
299
|
+
return answer.msg.contact as Contact
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
location = async (text: string, options?: QuestionParameters) => {
|
|
303
|
+
const markup = new Keyboard().requestLocation("Поделиться геопозицией 📍").oneTime(true).resized(true)
|
|
304
|
+
const message = await this.reply(text, { ...options, markup })
|
|
305
|
+
const answer = await this.conversation.waitFor(":location")
|
|
306
|
+
|
|
307
|
+
this.updateCtx(answer)
|
|
308
|
+
|
|
309
|
+
await (answer?.msg as any)?.delete?.().catch?.(() => {})
|
|
310
|
+
return answer.msg.location as Location
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
poll = async (text: string, options?: QuestionPollParameters) => {
|
|
314
|
+
const pollType = options?.poll?.type
|
|
315
|
+
const markup = new Keyboard().requestPoll("Отправить опрос 📊", pollType).oneTime(true).resized(true)
|
|
316
|
+
const message = await this.reply(text, { ...options, markup })
|
|
317
|
+
const answer = await this.conversation.waitFor(":poll")
|
|
318
|
+
|
|
319
|
+
this.updateCtx(answer)
|
|
320
|
+
|
|
321
|
+
await (answer?.msg as any)?.delete?.().catch?.(() => {})
|
|
322
|
+
return answer.msg.poll as Poll
|
|
323
|
+
}
|
|
324
|
+
|
|
202
325
|
private renderPaginationButtons = (
|
|
203
326
|
pagesCount: number,
|
|
204
327
|
currentPage: number,
|