Skip to content

Commit

Permalink
👾 Handle text-formatted links in messages (#9)
Browse files Browse the repository at this point in the history
Makes possible #8
  • Loading branch information
Rnbsov committed Mar 10, 2024
2 parents 9b3309a + 2c45bc4 commit 77f444f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
30 changes: 30 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/utils/getSourceLabel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function getSourceLabel(source: MessageOrigin) {
if (source) {
switch (source.type) {
case 'user':
sourceLabel = { name: `${source.sender_user.first_name} ${source.sender_user.last_name}` }
sourceLabel = { name: `${source.sender_user.first_name} ${source.sender_user.last_name || ''}` }
break;
case 'hidden_user':
sourceLabel = { name: source.sender_user_name }
Expand Down
9 changes: 8 additions & 1 deletion src/utils/getUrlAndLabels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ export function getUrlAndLabels(ctx: Filter<MyContext, 'message:entities:url'>)

// parse url from the message
if (startsWithUrl(message)) {
({ url, labels } = parseUrls(message)[0]);
;({ url, labels } = parseUrls(message)[0])
} else if (ctx.entities('text_link')) {
// handle case when user sends a message with text formatted link
const linkEntity = ctx.entities('text_link').find((entity) => entity.type === 'text_link')
if (linkEntity && linkEntity.url) {
url = linkEntity.url
}
labels = []
} else {
// retrieve the first url from the message
const urlMatch = message.match(/(?:https?:\/\/|www\.)\S+?(?=\s|$)/);
Expand Down

0 comments on commit 77f444f

Please sign in to comment.