Skip to content

Commit

Permalink
☄ Retrieve url from entity instead of regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Rnbsov committed Mar 15, 2024
1 parent 2d13ba9 commit f997755
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/utils/getUrlAndLabels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ export function getUrlAndLabels(ctx: Filter<MyContext, 'message:entities:url'>)
}
labels = []
} else {
// retrieve the first url from the message
const urlMatch = message.match(/(?:https?:\/\/|www\.)\S+?(?=\s|$)/);
url = urlMatch ? urlMatch[0] : '';
labels = [];
// retrieve the first url from the message/post
const urlEntity = ctx.entities('url').find((entity) => entity.type === 'url')
if (urlEntity && urlEntity.text) {
url = urlEntity.text
}
labels = []
}

// add default label
Expand Down

0 comments on commit f997755

Please sign in to comment.