-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#102) LinkGenerator: extract to a separate module
- Loading branch information
Showing
4 changed files
with
59 additions
and
25 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
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,34 @@ | ||
/// A module that generates links to various content from Telegram. | ||
module Emulsion.Telegram.LinkGenerator | ||
|
||
open Funogram.Telegram.Types | ||
|
||
type FunogramMessage = Funogram.Telegram.Types.Message | ||
|
||
type TelegramThreadLinks = { | ||
ContentLink: string option | ||
ReplyToContentLink: string option | ||
} | ||
with | ||
static member None: TelegramThreadLinks = { | ||
ContentLink = None | ||
ReplyToContentLink = None | ||
} | ||
|
||
let private getMessageLink (message: FunogramMessage) = | ||
match message with | ||
| { MessageId = id | ||
Chat = { Type = SuperGroup | ||
Username = Some chatName } } -> | ||
Some $"https://t.me/{chatName}/{id}" | ||
| _ -> None | ||
|
||
let private gatherMessageLink(message: FunogramMessage) = | ||
match message with | ||
| { Text = Some _} | { Poll = Some _ } -> None | ||
| _ -> getMessageLink message | ||
|
||
let gatherLinks(message: FunogramMessage): TelegramThreadLinks = { | ||
ContentLink = gatherMessageLink message | ||
ReplyToContentLink = message.ReplyToMessage |> Option.bind gatherMessageLink | ||
} |