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npm/telegram-bot-activitystreams@1.0.8/index.cjs/+esm","sourceRoot":"","sourcesContent":["/**\n * Bundled by jsDelivr using Rollup v2.79.2 and Terser v5.39.0.\n * Original file: /npm/telegram-bot-activitystreams@1.0.8/index.cjs\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","// file object params used, but not required - see https://github.com/qertis/telegram-bot-express\nconst {fromUnixTime} = require('date-fns/fromUnixTime');\n\nconst isTextLikeMarkdown = (text) => {\n  // Consecutive lines beginning with 1.\n  if (/(^|[\\n\\r])\\s*1\\.\\s.*\\s+1\\.\\s/gm.test(text)) {\n    return true;\n  }\n  // Link markdown\n  if (/!?\\[([^\\]]*)\\]\\(([^\\)]+)\\)/gm.test(text)) {\n    return true;\n  }\n  // Double underscores or asterisks when a left-right pair\n  if (/\\s(__|\\*\\*)(?!\\s)(.(?!\\1))+(?!\\s(?=\\1))/gm.test(text)) {\n    return true;\n  }\n  return false;\n}\n\nconst getFullName = (x) => {\n  if (x.first_name) {\n    return (x.first_name + ' ' + (x.last_name ?? '')).trimEnd();\n  }\n  return x.username;\n}\n\nconst actor = (x) => {\n  let type, name, id\n\n  if (x.channel_post) {\n    type = 'Group'\n    name = getFullName(x.channel_post.chat)\n    id = x.channel_post?.message_id\n  } else if (x.type === 'channel') {\n    type = 'Group'\n    name = getFullName(x)\n    id = x.id\n  } else if (x.sender_chat) {\n    type = 'Group'\n    name = getFullName(x.sender_chat) || x.sender_chat.username\n    id = String(x.sender_chat);\n  } else if (x.from) {\n    type = x.is_bot ? 'Service' : 'Person'\n    name = getFullName(x.from)\n    if (x.from.id) {\n      id = String(x.from.id)\n    }\n  } else {\n    type = x.is_bot ? 'Service' : 'Person'\n    name = getFullName(x)\n    if (x.id) {\n      id = String(x.id)\n    }\n  }\n\n  return {\n    type,\n    name,\n    id,\n  }\n};\n\nconst origin = (x) => {\n  switch (x.forward_origin?.type) {\n    case 'user': {\n      const user = x.forward_from ?? x.forward_origin.sender_user\n      return {\n        type: 'Person',\n        name: getFullName(user),\n        id: String(user.id),\n      }\n    }\n    case 'hidden_user': {\n      console.log(x)\n      return {\n        type: 'Person',\n        name: x.forward_sender_name,\n      }\n    }\n    default: {\n      return actor(x)\n    }\n  }\n};\n\nconst instrument = () => ({\n  type: 'Application',\n  name: 'Telegram',\n});\n\nconst sticker = ({sticker}) => ({\n  type: 'Object',\n  id: 'https://t.me/stickers' + '#' + sticker.set_name,\n  name: sticker.set_name,\n  content: sticker.emoji,\n});\n\nconst profile = (x) => ({\n  type: 'Profile',\n  name: getFullName(x.contact),\n  id: String(x.contact.user_id),\n  to: x.contact.phone_number ? `tel:+${x.contact.phone_number}` : null,\n});\n\nconst note = (x) => ({\n  type: 'Note',\n  content: x.text,\n  mediaType: isTextLikeMarkdown(x.text) ? 'text/markdown' : 'text/plain',\n});\n\nconst voice = (x) => ({\n  type: 'Audio',\n  url: x.voice?.file?.url,\n  duration: x.voice.duration,\n  mediaType: x.voice.mime_type,\n})\n\nconst audio = (x) => ({\n  type: 'Audio',\n  url: x.audio?.file?.url,\n  duration: x.audio.duration,\n  mediaType: x.audio.mime_type,\n  summary: x.caption,\n  name: x.audio.file_name,\n});\n\nconst thumbnail = (x) => {\n  const thumb = x.thumb || x.thumbnail;\n  if (thumb) {\n    return {\n      type: 'Image',\n      id: x.file_unique_id,\n      url: thumb?.file?.url,\n      width: thumb.width,\n      height: thumb.height,\n    }\n  }\n  return null\n}\n\nconst video = (x) => ({\n  type: 'Video',\n  summary: x.caption,\n  url: x.video?.file?.url,\n  duration: x.video.duration,\n  width: x.video.width,\n  height: x.video.height,\n  mediaType: x.video.mime_type,\n  icon: thumbnail(x.video),\n});\n\nconst videoNote = (x) => ({\n  type: 'Video',\n  url: x.video_note?.file?.url,\n  duration: x.video_note.duration,\n  icon: thumbnail(x.video_note),\n});\n\nconst document = (x) => ({\n  type: 'Document',\n  summary: x.caption,\n  url: x.document?.file?.url,\n  mediaType: x.document.mime_type,\n  name: x.document.file_name,\n  icon: thumbnail(x.document),\n});\n\nconst tag = (x) => ({\n  id: x,\n  name: '#' + x,\n});\n\nconst event = (x) => ({\n  type: 'Event',\n  name: x.text,\n});\n\nconst place = (x) => ({\n  type: 'Place',\n  latitude: x.location.latitude,\n  longitude: x.location.longitude,\n});\n\nconst getHashtagsFromEntities = (entities, text) => {\n  return entities\n      .filter((entity) => entity.type === 'hashtag')\n      .map(entity => {\n        // eslint-disable-next-line unicorn/prefer-string-slice\n        const hashtag = text.substr(\n            entity.offset + 1,\n            entity.length - 1,\n        );\n        return hashtag;\n      });\n}\n\nfunction getHashtagsFromText(message) {\n  const hashtags = new Set();\n  if (Array.isArray(message.entities) && message.entities.length > 0) {\n    getHashtagsFromEntities(message.entities, message.text).forEach((hashtag) => {\n      hashtags.add(hashtag);\n    });\n  }\n  return [...hashtags];\n}\n\nfunction getHashtagsFromCaption(message) {\n  const hashtags = new Set();\n  if (Array.isArray(message.caption_entities) && message.caption_entities.length > 0) {\n    getHashtagsFromEntities(message.caption_entities, message.caption).forEach((hashtag) => {\n      hashtags.add(hashtag);\n    });\n  }\n  return [...hashtags];\n}\n\nfunction objects(message) {\n  const objects = [];\n\n  if (message.text) {\n    if (Array.isArray(message.entities)) {\n      let dub = message.text;\n      message.entities.filter(entity => entity.type === 'text_link').reverse().forEach(entity => {\n        const text = message.text.substring(entity.offset, entity.offset + entity.length);\n        dub = dub.replace(text, `[${text}](${entity.url})`);\n      });\n      message.text = dub;\n    }\n\n    const textHashtags = getHashtagsFromText(message);\n    let n;\n    if (Array.isArray(message.entities) && message.entities.some(e => e.type === 'bot_command')) {\n      n = event(message);\n    } else {\n      n = note(message);\n    }\n\n    if (textHashtags.length > 0) {\n      n.tag = textHashtags.map(h => tag(h));\n    }\n    objects.push(n);\n  }\n  if (message.contact) {\n    objects.push(profile(message));\n  }\n  if (message.photo) {\n    const captionHashtags = getHashtagsFromCaption(message);\n    const photoHQ = message.photo.map(photo => {\n      const image = {\n        type: 'Image',\n        width: photo.width,\n        height: photo.height,\n        url: photo?.file?.url,\n        summary: message?.caption,\n      };\n      if (captionHashtags.length > 0) {\n        image.tag = captionHashtags.map(h => tag(h));\n      }\n      return image;\n    }).reduce((acc, photo) => {\n      if (acc.width < photo.width) {\n        acc = photo;\n      }\n      return acc;\n    }, { width: 0 });\n    objects.push(photoHQ);\n  }\n  if (message.video) {\n    objects.push(video(message));\n  }\n  if (message.document) {\n    objects.push(document(message));\n  }\n  if (message.voice) {\n    objects.push(voice(message));\n  }\n  if (message.location) {\n    objects.push(place(message));\n  }\n  if (message.sticker) {\n    objects.push(sticker(message));\n  }\n  if (message.audio) {\n    objects.push(audio(message));\n  }\n  if (message.video_note) {\n    objects.push(videoNote(message));\n  }\n\n  return objects;\n}\n\nfunction time(date = Math.round(new Date().getTime() / 1000)) {\n  return fromUnixTime(date).toISOString();\n}\n\nmodule.exports = (message) => {\n  const context = 'https://www.w3.org/ns/activitystreams';\n\n  if (message.channel_post) {\n    return {\n      '@context': context,\n      type: 'Activity',\n      instrument: instrument(),\n      object: objects(message.channel_post),\n      actor: actor(message.channel_post.chat),\n      origin: origin(message),\n      startTime: time(message.channel_post.date),\n    }\n  } else if (message.sender_chat) {\n    return {\n      '@context': context,\n      type: 'Activity',\n      instrument: instrument(),\n      object: objects(message),\n      actor: actor(message.sender_chat),\n      origin: origin(message),\n      startTime: time(message.date),\n    }\n  }\n  return {\n    '@context': context,\n    type: 'Activity',\n    summary: message.type,\n    instrument: instrument(),\n    actor: actor(message.from),\n    object: objects(message),\n    target: actor(message.chat),\n    origin: origin(message),\n    startTime: time(message.date),\n  }\n}\n"]}