Skip to content

feat: Add chat.getURLPreview endpoint - #30478

Merged
kodiakhq[bot] merged 13 commits into
developfrom
new/preview-url-endpoint
Jan 19, 2024
Merged

feat: Add chat.getURLPreview endpoint#30478
kodiakhq[bot] merged 13 commits into
developfrom
new/preview-url-endpoint

Conversation

@matheusbsilva137

@matheusbsilva137 matheusbsilva137 commented Sep 22, 2023

Copy link
Copy Markdown
Contributor

Proposed changes (including videos or screenshots)

  • Add chat.getURLPreview endpoint to enable users to retrieve URL previews prior to sending messages.

Issue(s)

Steps to test or reproduce

This endpoint requires url and roomId properties.
Example request (cURL):

curl --request GET 'http://localhost:3000/api/v1/chat.getURLPreview?roomId=650b53843e77b9b901c7cba6&url=https://www.youtube.com/watch?v=no050HN4ojo' \
--header 'X-Auth-Token: AlBrFCgo7ChqzKhTP0dViC-jS7N_HL4vyQT2E-fs9x0' \
--header 'X-User-Id: iGiuqqMDCNMXDhKcY'
Example response
{
"urlPreview": {
  "url": "https://www.youtube.com/watch?v=no050HN4ojo",
  "meta": {
    "oembedUrl": "https://www.youtube.com/watch?v=no050HN4ojo",
    "oembedTitle": "Rocket.Chat - El líder de comunicación de código abierto",
    "oembedAuthorName": "Rocket.Chat",
    "oembedAuthorUrl": "https://www.youtube.com/@RocketChatApp",
    "oembedType": "video",
    "oembedVersion": "1.0",
    "oembedProviderName": "YouTube",
    "oembedProviderUrl": "https://www.youtube.com/",
    "oembedThumbnailUrl": "https://i.ytimg.com/vi/no050HN4ojo/hqdefault.jpg",
    "oembedHtml": "<iframe style=\"max-width: 100%;width:400px;height:225px\" width=\"200\" height=\"113\" src=\"https://www.youtube.com/embed/no050HN4ojo?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen title=\"Rocket.Chat - El líder de comunicación de código abierto\"></iframe>"
  },
  "headers": {
    "contentType": "application/json"
  },
  "parsedUrl": {
    "host": "www.youtube.com",
    "hash": null,
    "pathname": "/oembed",
    "protocol": "https:",
    "port": null,
    "query": {
      "maxheight": "200",
      "url": "https://www.youtube.com/watch?v=no050HN4ojo"
    },
    "search": "?maxheight=200&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dno050HN4ojo",
    "hostname": "www.youtube.com",
    "slashes": true,
    "auth": null,
    "path": "/oembed?maxheight=200&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dno050HN4ojo",
    "href": "https://www.youtube.com/oembed?maxheight=200&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dno050HN4ojo"
  },
  "ignoreParse": true
},
"success": true
}
Example request for sending a message with previously generated previews
  • The parseUrls param must be sent so that previews are not re-generated (when this param is sent, we use the previews sent to the endpoint, no new ones are generated)
curl -H "X-Auth-Token: AlBrFCgo7ChqzKhTP0dViC-jS7N_HL4vyQT2E-fs9x0" \
   -H "X-User-Id: iGiuqqMDCNMXDhKcY" \
   -H "Content-type:application/json" \
   http://localhost:3000/api/v1/chat.sendMessage \
   -d '{"message": { "rid": "GENERAL", "msg": "This is a test! https://www.youtube.com/watch?v=no050HN4ojo", "urls": [{"url":"https://www.youtube.com/watch?v=no050HN4ojo","meta":{"oembedUrl":"https://www.youtube.com/watch?v=no050HN4ojo","oembedTitle":"Rocket.Chat - El líder de comunicación de código abierto","oembedAuthorName":"Rocket.Chat","oembedAuthorUrl":"https://www.youtube.com/@RocketChatApp","oembedType":"video","oembedVersion":"1.0","oembedProviderName":"YouTube","oembedProviderUrl":"https://www.youtube.com/","oembedThumbnailUrl":"https://i.ytimg.com/vi/no050HN4ojo/hqdefault.jpg","oembedHtml":"<iframe style=\"max-width: 100%;width:400px;height:225px\" width=\"200\" height=\"113\" src=\"https://www.youtube.com/embed/no050HN4ojo?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen title=\"Rocket.Chat - El líder de comunicación de código abierto\"></iframe>"},"headers":{"contentType":"application/json"},"parsedUrl":{"host":"www.youtube.com","hash":null,"pathname":"/oembed","protocol":"https:","port":null,"query":{"maxheight":"200","url":"https://www.youtube.com/watch?v=no050HN4ojo"},"search":"?maxheight=200&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dno050HN4ojo","hostname":"www.youtube.com","slashes":true,"auth":null,"path":"/oembed?maxheight=200&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dno050HN4ojo","href":"https://www.youtube.com/oembed?maxheight=200&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dno050HN4ojo"},"ignoreParse":true}], "parseUrls": false }}'

Further comments

Note
Returned URL previews contain the ignoreParse property so that they are not retrieved again when attached to a message and sent.

Note
Removed attachments check on rocketUrlParser since the attachment property is not returned from getUrlMetaWithCache (see this line)

TC-938

@changeset-bot

changeset-bot Bot commented Sep 22, 2023

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a73e494

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 30 packages
Name Type
@rocket.chat/meteor Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch
@rocket.chat/core-services Patch
@rocket.chat/cron Patch
@rocket.chat/gazzodown Patch
@rocket.chat/livechat Patch
@rocket.chat/model-typings Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/stream-hub-service Patch
@rocket.chat/api-client Patch
@rocket.chat/license Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/ddp-client Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/models Patch
@rocket.chat/ui-client Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/instance-status Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov

codecov Bot commented Sep 22, 2023

Copy link
Copy Markdown

Codecov Report

Attention: 8 lines in your changes are missing coverage. Please review.

Comparison is base (6ca6871) 49.53% compared to head (a73e494) 49.56%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #30478      +/-   ##
===========================================
+ Coverage    49.53%   49.56%   +0.02%     
===========================================
  Files         3311     3311              
  Lines        81470    81473       +3     
  Branches     16706    16706              
===========================================
+ Hits         40360    40385      +25     
+ Misses       36408    36397      -11     
+ Partials      4702     4691      -11     
Flag Coverage Δ
e2e 53.20% <ø> (+0.02%) ⬆️
e2e-api 40.67% <68.00%> (+0.03%) ⬆️
unit 76.51% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

@matheusbsilva137
matheusbsilva137 marked this pull request as ready for review September 23, 2023 02:18
@matheusbsilva137
matheusbsilva137 requested review from a team as code owners September 23, 2023 02:18
heitortanoue
heitortanoue previously approved these changes Sep 27, 2023
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Sep 29, 2023
@kodiakhq kodiakhq Bot removed the stat: ready to merge PR tested and approved waiting for merge label Oct 2, 2023
@kodiakhq

kodiakhq Bot commented Oct 2, 2023

Copy link
Copy Markdown
Contributor

This PR currently has a merge conflict. Please resolve this and then re-add the ['stat: ready to merge', 'automerge'] label.

@dionisio-bot dionisio-bot Bot added stat: ready to merge PR tested and approved waiting for merge and removed stat: conflict labels Oct 2, 2023
@dionisio-bot dionisio-bot Bot added stat: ready to merge PR tested and approved waiting for merge and removed stat: ready to merge PR tested and approved waiting for merge labels Oct 2, 2023
Comment thread apps/meteor/app/oembed/server/server.ts
Comment thread apps/meteor/app/oembed/server/server.ts
@scuciatto scuciatto added this to the 6.6 milestone Dec 4, 2023
Comment thread apps/meteor/app/api/server/v1/chat.ts Outdated
Comment thread apps/meteor/app/api/server/v1/chat.ts
Comment thread apps/meteor/app/oembed/server/server.ts Outdated
@dionisio-bot dionisio-bot Bot added stat: ready to merge PR tested and approved waiting for merge and removed stat: ready to merge PR tested and approved waiting for merge labels Dec 12, 2023
@dionisio-bot dionisio-bot Bot added stat: ready to merge PR tested and approved waiting for merge and removed stat: ready to merge PR tested and approved waiting for merge labels Dec 12, 2023
@dionisio-bot dionisio-bot Bot added stat: ready to merge PR tested and approved waiting for merge and removed stat: ready to merge PR tested and approved waiting for merge labels Dec 15, 2023
@kodiakhq kodiakhq Bot removed the stat: ready to merge PR tested and approved waiting for merge label Dec 18, 2023
@kodiakhq

kodiakhq Bot commented Dec 18, 2023

Copy link
Copy Markdown
Contributor

This PR currently has a merge conflict. Please resolve this and then re-add the ['stat: ready to merge', 'automerge'] label.

@dionisio-bot dionisio-bot Bot added stat: ready to merge PR tested and approved waiting for merge and removed stat: conflict labels Dec 20, 2023
@dionisio-bot dionisio-bot Bot added stat: ready to merge PR tested and approved waiting for merge and removed stat: ready to merge PR tested and approved waiting for merge labels Jan 9, 2024
@dionisio-bot dionisio-bot Bot added stat: ready to merge PR tested and approved waiting for merge and removed stat: ready to merge PR tested and approved waiting for merge labels Jan 19, 2024
@kodiakhq
kodiakhq Bot merged commit fdd9852 into develop Jan 19, 2024
@kodiakhq
kodiakhq Bot deleted the new/preview-url-endpoint branch January 19, 2024 17:15
gabriellsh added a commit that referenced this pull request Jan 19, 2024
…/emailEmoji

* 'develop' of github.com:RocketChat/Rocket.Chat: (166 commits)
  feat: Add `chat.getURLPreview` endpoint (#30478)
  chore: QoL changes for Omnichannel (#31468)
  fix: add missing labels to UsersByTimeOfTheDaySection (#31368)
  refactor: Remove `Notifications` module (#31463)
  i18n: zh translation error (#21600)
  feat: `Bubble` on new messages indicators (#31478)
  test: fix flaky setGuestName test (#31486)
  Release 6.5.3
  chore: RateLimiter to async (#31480)
  chore: Revert "chore: Add missing changeset file" (#31481)
  chore: Remove `MessageContentBody` additional styles (#31476)
  chore: Replace `Notifications` module in favor of `SDK` inside CachedCollection (#31424)
  chore: improve backend startup (#31479)
  chore: fix embedded livechat tests (#31477)
  fix: Department name being double escaped (#31454)
  chore: Remove unnecessary changeset file (#31472)
  chore(eslint-config): Include missing ESLint configuration for React (#30977)
  refactor: Replace `Notifications` module in favor of `sdk` for Omnichannel/WebRTC (#31460)
  refactor: Replace `Notifications` module in favor of `sdk` for Video Conf (#31462)
  feat: Add support to cancel editing message action (#31347)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: ready to merge PR tested and approved waiting for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants