Giter VIP home page Giter VIP logo

Comments (7)

sampoder avatar sampoder commented on September 10, 2024

oooh and emoji

from scrappy.

lachlanjc avatar lachlanjc commented on September 10, 2024

Yeah I was going to implement on the frontend but actually it’d be way more performant to do backend-side

from scrappy.

sampoder avatar sampoder commented on September 10, 2024

export const formatText = (text) => {
  //<@USLACKBOT>
  // if (text.includes('<@')) {
  //   const userId = text.split('@').pop().split('>')[0]
  //   console.log(`userId`, userId)
  //   const userProfile = await fetch(`https://slack.com/api/users.profile.get?token=${process.env.SLACK_BOT_TOKEN}&user=${userId}`)
  // }
  let userIds = text.split(' ').filter((word) => word.includes('<@U'))
  if (userIds.length == 0) return text

  userIds.forEach(async (userId) => {
    try {
      const id = userId.split('@').pop().split('>')[0]
      const userProfile = await fetch(
        `https://slack.com/api/users.profile.get?token=${process.env.SLACK_BOT_TOKEN}&user=${id}`
      ).then((r) => r.json())
      console.log(userProfile)
      const displayName = userProfile.profile.display_name
      userId = `@${displayName}`
    } catch (err) {
      console.log(err)
    }
  })
  console.log(userIds.join(' '))
  return userIds.join(' ')
}

from scrappy.

lachlanjc avatar lachlanjc commented on September 10, 2024

You’re an icon, thank you so much! @MatthewStanciu will test out/implement today.

from scrappy.

sampoder avatar sampoder commented on September 10, 2024

oh lol i didnt write this code, i found it in pre existing code in this repo

from scrappy.

MatthewStanciu avatar MatthewStanciu commented on September 10, 2024

Yep this is my code that I wrote in the beginning stages of scrappy but never finished. It doesn’t work, but it’s pretty close. If anyone wants to help get it all the way there, it would be super appreciated :)

from scrappy.

sampoder avatar sampoder commented on September 10, 2024

Try to do this, Javascript is confusing

#26 makes it a bit cleaner

Well it really only removes the angle brackets and wraps it in a span element with a specific class

from scrappy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.