Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 24 additions & 45 deletions scripts/yodev.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// hubot yodev <query> - Busca ofertas de trabajo relacionadas con el query
//
// Examples:
// hubot yodev javascript - Busca trabajos de JavaScript
// hubot yodev javascript - Busca trabajos de JavaScript
//
// Author:
// @jorgeepunan
Expand All @@ -36,7 +36,7 @@ module.exports = (robot) => {
return res.send(text)
}

send(`🔎 Buscando *${query}*... explorando oportunidades en yodev.dev 💼`)
send(`🔎 Buscando *${query}*... explorando oportunidades en yodev.dev 🚀 💼`)

https.get(url, (response) => {
let data = ''
Expand All @@ -63,68 +63,47 @@ module.exports = (robot) => {
}

const limitedJobs = jobs.slice(0, 5)
const blocks = [
{
type: 'section',
text: {
type: 'mrkdwn',
text: `Encontré ${totalJobs} resultado(s):`
}
const blocks = []
blocks.push({
type: 'section',
text: {
type: 'mrkdwn',
text: `✅ Encontré ${totalJobs} resultado(s) en yodev.dev:`
}
]
})

limitedJobs.forEach((job) => {
blocks.push({ type: 'divider' })

const lines = [`*<${job.url}|${job.title}>*`]
lines.push(`*Empresa:* ${job.company}`)
lines.push(`*Ubicación:* ${job.location}`)
if (job.posted || job.date) lines.push(`*Publicado:* ${job.posted || job.date}`)
if (job.salary) lines.push(`*Sueldo:* ${job.salary}`)
if (job.type) lines.push(`*Tipo:* ${job.type}`)
if (job.source) lines.push(`*Fuente:* ${job.source}`)
blocks.push({
type: 'divider'
})

blocks.push({
type: 'section',
text: {
type: 'mrkdwn',
text: lines.join('\n')
text: `*<${job.url}|${job.title}>*\n* · Empresa:* ${job.company}\n* · Ubicación:* ${job.location}\n* · Publicado:* ${job.posted || job.date || ''}${job.salary ? `\n* · Sueldo:* ${job.salary}` : ''}${job.type ? `\n* · Tipo:* ${job.type}` : ''}${job.source ? `\n* · Fuente:* ${job.source}` : ''}`
}
})
})

if (viewMoreUrl) {
blocks.push({ type: 'divider' })
blocks.push({
type: 'context',
elements: [{
type: 'mrkdwn',
text: `¿Quieres ver más ofertas? Visita: <${viewMoreUrl}|yodev.dev>`
}]
type: 'divider'
})
}

if (isSlack && robot.adapter.client && robot.adapter.client.web) {
const options = { unfurl_links: false, unfurl_media: false, as_user: true, blocks }
return robot.adapter.client.web.chat.postMessage(res.message.room, '', options)
blocks.push({
type: 'section',
text: {
type: 'mrkdwn',
text: `🔍 ¿Quieres ver más ofertas? Visita: <${viewMoreUrl}>`
}
})
}

// Fallback para non-Slack
const messages = limitedJobs.map((job) => {
const lines = [`*${job.title}*`]
lines.push(`Empresa: ${job.company}`)
lines.push(`Ubicación: ${job.location}`)
lines.push(`Postulación: ${job.url}`)
if (job.posted || job.date) lines.push(`Publicado: ${job.posted || job.date}`)
if (job.salary) lines.push(`Sueldo: ${job.salary}`)
if (job.type) lines.push(`Tipo: ${job.type}`)
if (job.source) lines.push(`Fuente: ${job.source}`)
return lines.join('\n')
robot.adapter.client.web.chat.postMessage({
channel: res.message.room,
blocks
})
if (viewMoreUrl) {
messages.push(`\n¿Quieres ver más ofertas? Visita: ${viewMoreUrl}`)
}
send(`😎 Encontré ${totalJobs} resultado(s):\n\n${messages.join('\n\n---\n\n')}`)
} catch (error) {
robot.logger.error(`Error al parsear la respuesta: ${error.message}`)
send('Ups! Ocurrió un error al procesar las ofertas de trabajo de yodev.dev. 😱')
Expand Down
Loading