Web Scraping & Bots · Lección

Envío de alertas y notificaciones

Haga que sus bots desplegados sean accionables enviando alertas por correo electrónico, Slack y webhooks cuando encuentren algo o fallen.

Lección 4 de 413 pasos

Envío de alertas y notificaciones es una lección gratuita de Web Scraping & Bots en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Web Scraping & Bots, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Web Scraping & Bots incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

From Data to Action

A deployed bot that quietly stores data is only half useful. The real value comes when it notifies you: a price dropped, a keyword appeared, or the bot itself broke.

This lesson covers wiring bots to notification channels.

Choosing a Channel

Pick the channel that fits urgency:

  • Email for digests and non-urgent reports.
  • Slack/Discord for team-visible real-time alerts.
  • Push/SMS for urgent, must-see events.

Sending Email

Python's smtplib sends email through any SMTP server. Build the message, connect securely, and send.

import smtplib
from email.message import EmailMessage

msg = EmailMessage()
msg['Subject'] = 'Price Alert'
msg['From'] = 'bot@example.com'
msg['To'] = 'me@example.com'
msg.set_content('Widget dropped to $7.99')

with smtplib.SMTP_SSL('smtp.example.com', 465) as s:
    s.login('bot@example.com', 'password')
    s.send_message(msg)

Slack via Webhook

Slack incoming webhooks accept a simple JSON POST. No SDK required, just a URL you keep secret.

import requests

requests.post(
    'https://hooks.slack.com/services/XXX/YYY/ZZZ',
    json={'text': 'Price dropped to $7.99 :tada:'}
)

Rich Messages

Most chat webhooks support structured blocks: titles, links, and fields. A well-formatted alert is faster to act on than a wall of text.

payload = {
  'blocks': [
    {'type': 'section', 'text': {'type': 'mrkdwn', 'text': '*Price Alert*\nWidget: $7.99'}}
  ]
}
requests.post(webhook_url, json=payload)

Generic Webhooks

Webhooks let your bot trigger anything: a Zapier flow, a custom server, or another service. Send a JSON payload and let the receiver decide what to do.

requests.post('https://my-endpoint.example/hook',
              json={'event': 'price_drop', 'price': 7.99})

Alerting Only on Change

Do not notify on every run. Compare against the last known state and alert only when something meaningful changes, to avoid notification fatigue.

if new_price < last_price:
    send_alert('price dropped to ' + str(new_price))
last_price = new_price

Throttling and Deduplication

Suppress repeat alerts for the same event within a window. Track recently-sent keys so a flapping condition does not spam you.

import time

last_sent = {}
def alert_once(key, msg, cooldown=3600):
    now = time.time()
    if now - last_sent.get(key, 0) > cooldown:
        send_alert(msg)
        last_sent[key] = now

Alerting on Bot Failure

Notify yourself when the bot itself breaks, not just on data events. Wrap the run and send an alert from the except block so silent crashes never go unnoticed.

try:
    run_bot()
except Exception as e:
    send_alert('Bot crashed: ' + str(e))
    raise

Keeping Secrets Safe

Webhook URLs, SMTP passwords, and API tokens are credentials. Store them in environment variables or a secrets manager, never hard-coded in the repository.

import os
webhook = os.environ['SLACK_WEBHOOK_URL']

Confirming Delivery

A notification call can silently fail. Check the response status and log it, so a broken webhook does not leave you unaware that alerts stopped arriving.

resp = requests.post(webhook, json=payload)
if not resp.ok:
    log.error('alert delivery failed: %s', resp.status_code)

Quick Check

Test your understanding of notifications.

Recap

You learned to make deployed bots actionable: choose a channel, send email via smtplib, post to Slack and generic webhooks, format rich messages, alert only on change, throttle duplicates, notify on bot failure, and keep credentials in environment variables.

Gratis para empezar

Aprende Python con un tutor de IA — gratis

Escribe y ejecuta código real en tu navegador, obtén ayuda instantánea de un tutor de IA disponible 24/7 y continúa donde lo dejaste en la web o en la aplicación.

Cursos
12
Lecciones
48

Preguntas frecuentes

¿La lección «Envío de alertas y notificaciones» es gratis?

Sí — el texto completo de «Envío de alertas y notificaciones» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Web Scraping & Bots, actualiza a CoddyKit PRO. El curso de Web Scraping & Bots incluye 4 lecciones en total.

¿Qué aprenderé en «Envío de alertas y notificaciones»?

Haga que sus bots desplegados sean accionables enviando alertas por correo electrónico, Slack y webhooks cuando encuentren algo o fallen. Practicas Web Scraping & Bots con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Web Scraping & Bots?

No se requiere experiencia previa. Web Scraping & Bots en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.

¿Cuánto tiempo toma la lección «Envío de alertas y notificaciones»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Web Scraping & Bots?

Sí. Cada lección de Web Scraping & Bots incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Creación de un bot de seguimiento de precios
  2. Creación de un monitor de redes sociales
  3. Implementación de bots en plataformas en la nube
  4. Envío de alertas y notificaciones
← Volver a Web Scraping & Bots