-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinline.ts
More file actions
62 lines (56 loc) · 1.6 KB
/
Copy pathinline.ts
File metadata and controls
62 lines (56 loc) · 1.6 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
By Aditya < https://xditya.me >
*/
import { Composer } from "grammy/mod.ts";
import { InlineQueryResultPhoto } from "grammy/types.ts";
import imageSearch from "../helpers/pexel.ts";
const composer = new Composer();
composer.on("inline_query", async (ctx) => {
const query = ctx.inlineQuery.query;
if (!query) {
return await ctx.answerInlineQuery(
[
{
type: "article",
id: "null",
title: "Pexel Search",
input_message_content: {
message_text:
"Please enter a search query!\n\nJoin @BotzHub for more cool bots!",
},
description: "Enter a query to search!",
},
],
{ cache_time: 30 * 60 },
);
}
const res = await imageSearch(query);
const pics = res?.photos;
if (pics == undefined || pics.length == 0) {
return await ctx.answerInlineQuery(
[
{
type: "article",
id: "Not Found",
title: "Pexel Search - No Results!",
input_message_content: {
message_text:
"Please enter a search query.\nJoin @BotzHub for more cool bots!",
},
description: "No results found!",
},
],
);
}
const results: InlineQueryResultPhoto[] = pics.map((pic) => ({
type: "photo",
id: pic.id.toString(),
photo_url: pic.src.original,
thumb_url: pic.src.tiny,
caption:
`Photo by [${pic.photographer}](${pic.photographer_url}) on [Pexel](${pic.url})`,
parse_mode: "Markdown",
}));
await ctx.answerInlineQuery(results, { cache_time: 30 * 60 });
});
export default composer;