-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from mi3lix9/feat/inline-query
add inline query handler
- Loading branch information
Showing
4 changed files
with
61 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { InlineQueryResultArticle } from "grammy/types"; | ||
import { search } from "../jellyseerr"; | ||
import { createTemplate } from "./createTemplate"; | ||
import type { MyContext } from "./types"; | ||
import type { Filter } from "grammy"; | ||
|
||
export async function inlineQueryHandler( | ||
ctx: Filter<MyContext, "inline_query"> | ||
) { | ||
const query = ctx.inlineQuery.query.trim(); | ||
|
||
if (query === "") { | ||
return; // Ignore empty queries | ||
} | ||
|
||
const results = await search({ query }); | ||
|
||
// Format the results to send as inline query answers | ||
const inlineResults: InlineQueryResultArticle[] = results | ||
.filter((result) => typeof result.posterPath !== "undefined") | ||
.map((result) => ({ | ||
type: "article", | ||
id: String(result.mediaId), | ||
title: result.mediaType + ": " + result.title, | ||
input_message_content: { | ||
message_text: createTemplate({ | ||
title: result.title, | ||
overview: result.overview ?? "", | ||
releaseDate: result.releaseDate ?? "", | ||
mediaType: result.mediaType, | ||
}), | ||
}, | ||
description: result.overview, | ||
thumb_url: result.posterPath, | ||
})); | ||
|
||
// Answer the inline query | ||
await ctx.answerInlineQuery(inlineResults); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters