diff --git a/src/index.ts b/src/index.ts index 96b1079..7c34e51 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,7 +13,7 @@ const newlinesRegex = /(?:\r\n|\r|\n)/; */ export function parseString( string: string, - options: ParseStringOptions = { parseAttachments: false }, + options: ParseStringOptions = { parseAttachments: false, parsePollMessage: false }, ): Message[] { const lines = string.split(newlinesRegex); return parseMessages(makeArrayOfMessages(lines), options); diff --git a/src/parser.ts b/src/parser.ts index 24916d2..a60b5ac 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -81,7 +81,7 @@ function parseMessages( options: ParseStringOptions = {}, ): Message[] { let { daysFirst } = options; - const { parseAttachments } = options; + const { parseAttachments, parsePollMessage } = options; // Parse messages with regex const parsed = messages.map(obj => { @@ -138,12 +138,26 @@ function parseMessages( message, }; + // Optionally parse attachments if (parseAttachments) { const attachment = parseMessageAttachment(message); if (attachment) finalObject.attachment = attachment; } + function checkPoll(message) { + return true + } + + function parsePoll(message) { + return message + } + + if (parsePollMessage && checkPoll(message)) { + finalObject.poll = parsePoll(message) + + } + return finalObject; }); } diff --git a/src/types.ts b/src/types.ts index 3eb3074..5996ebe 100644 --- a/src/types.ts +++ b/src/types.ts @@ -10,6 +10,10 @@ interface Attachment { fileName: string; } +interface Poll { + +} + interface Message { /** * The date of the message. @@ -28,6 +32,11 @@ interface Message { * `parseAttachments` to `true`. */ attachment?: Attachment; + /** + * Available for messages containing attachments when setting the option + * `parseAttachments` to `true`. + */ + polls?: Poll[] } interface ParseStringOptions { @@ -45,6 +54,10 @@ interface ParseStringOptions { * `attachment` property. */ parseAttachments?: boolean; + /** + * Specify if parses polls + */ + parsePollMessage?: boolean } export { RawMessage, Attachment, Message, ParseStringOptions };