We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
https://api.github.com/vorant94/sofash/blob/fcb3ff714b19baf963f745027eebdd11e63af32c/apps/server/src/parse/parsers/telegram.parser.ts#L56
import { type Parser } from './parser.js'; import { type TelegramRawEventJob } from 'mq'; import { type EventEntity } from 'db'; import { type Logger } from 'logger'; import { type message, type MessageContent, type messagePhoto, type messageText, } from 'tdlib-types'; import { type Llm } from 'llm'; import { type DeepPartial } from 'typeorm'; export class TelegramParser implements Parser<TelegramRawEventJob> { readonly #logger: Logger; readonly #llm: Llm; constructor(logger: Logger, llm: Llm) { this.#logger = logger.clone(TelegramParser.name); this.#llm = llm; } async parseRawEventJob( rawEvent: TelegramRawEventJob, ): Promise<DeepPartial<EventEntity>> { this.#logger.debug( `parseRawEventJob started: ${JSON.stringify(rawEvent, null, 2)}`, ); const message = this.#extractMessage(rawEvent.content); const eventData = await this.#llm.extractEventData(message); const event: DeepPartial<EventEntity> = { title: eventData.title, description: eventData.description, price: eventData.price, detailsUrl: 'test', sourceId: rawEvent.eventSource.id, sourceMessageId: rawEvent.content.id.toString(), }; if (eventData.startingAt != null) { event.startingAt = new Date(eventData.startingAt); } if (eventData.endingAt != null) { event.endingAt = new Date(eventData.endingAt); } this.#logger.debug( `parseRawEventJob finished: ${JSON.stringify(event, null, 2)}`, ); return event; } // TODO: make declarative like with scrappers #extractMessage({ content }: message): string { if (this.#isTextContent(content)) { return content.text.text; } else if (this.#isImageContent(content)) { return content.caption.text; } else { throw new Error( `Can't extract message from with content of type [${content._}]`, ); } } #isTextContent(content: MessageContent): content is messageText { return content._ === 'messageText'; } #isImageContent(content: MessageContent): content is messagePhoto { return content._ === 'messagePhoto'; } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
https://api.github.com/vorant94/sofash/blob/fcb3ff714b19baf963f745027eebdd11e63af32c/apps/server/src/parse/parsers/telegram.parser.ts#L56
The text was updated successfully, but these errors were encountered: