Overview
The bot sends different messages based on the time of day. This guide shows you how to customize these messages to match your needs.
Message Configuration
Messages are defined in bot.py at line 13. Here’s the current implementation:
# Determinar si es entrada o salida según la hora (UTC)
# Ejemplo: Si estás en México, 15:00 UTC es 9:00 AM
ahora_hora = datetime.datetime.utcnow().hour
mensaje = "Aldo Tolentino \n Entrada \n 9:00 AM" if ahora_hora < 18 else "Aldo Tolentino \n Salida \n 3:00 PM"
Understanding the Time Logic
The bot uses UTC hour to determine which message to send:
Time Check
The condition ahora_hora < 18 checks if the current UTC hour is before 18:00 (6:00 PM UTC). ahora_hora = datetime.datetime.utcnow().hour
If UTC hour < 18 → Send “Entrada” (Check-in) message
If UTC hour ≥ 18 → Send “Salida” (Check-out) message
UTC Consideration
Since GitHub Actions runs in UTC, the threshold hour depends on your timezone: Timezone Morning Run (Local) UTC Hour Evening Run (Local) UTC Hour CST (UTC-6) 9:00 AM 15 3:00 PM 21 PST (UTC-8) 9:00 AM 17 3:00 PM 23 EST (UTC-5) 9:00 AM 14 3:00 PM 20
With the current threshold of 18, any run before 6:00 PM UTC sends “Entrada”, and any run at or after sends “Salida”.
Customizing Message Content
Basic Customization
Replace the name and times with your own:
mensaje = "Your Name \n Entrada \n 8:30 AM" if ahora_hora < 18 else "Your Name \n Salida \n 5:00 PM"
Use \n for line breaks in the message. This creates a multi-line WhatsApp message.
Add Department
Add Employee ID
Add Location
mensaje = "Your Name \n Development Team \n Entrada \n 9:00 AM" if ahora_hora < 18 else "Your Name \n Development Team \n Salida \n 3:00 PM"
mensaje = "Employee: Your Name \n ID: 12345 \n Entrada - 9:00 AM" if ahora_hora < 18 else "Employee: Your Name \n ID: 12345 \n Salida - 3:00 PM"
mensaje = "Your Name \n Entrada - 9:00 AM \n Oficina Central" if ahora_hora < 18 else "Your Name \n Salida - 3:00 PM \n Oficina Central"
Dynamic Content
Including Actual Timestamp
Instead of hardcoded times, include the actual execution time:
import datetime
def enviar_registro ():
instance_id = os.getenv( 'INSTANCE_ID' )
token = os.getenv( 'TOKEN' )
group_id = os.getenv( 'GROUP_ID' )
# Get current time in your timezone
ahora_utc = datetime.datetime.utcnow()
ahora_hora = ahora_utc.hour
# Convert to your local timezone (example: UTC-6 for CST)
offset_horas = - 6
ahora_local = ahora_utc + datetime.timedelta( hours = offset_horas)
hora_formateada = ahora_local.strftime( "%I:%M %p" )
if ahora_hora < 18 :
mensaje = f "Your Name \n Entrada \n { hora_formateada } "
else :
mensaje = f "Your Name \n Salida \n { hora_formateada } "
# ... rest of the function
Be careful with timezone offsets during Daylight Saving Time transitions. Consider using the pytz library for more robust timezone handling.
Including Day of Week
Add the day of the week to your message:
import datetime
def enviar_registro ():
instance_id = os.getenv( 'INSTANCE_ID' )
token = os.getenv( 'TOKEN' )
group_id = os.getenv( 'GROUP_ID' )
ahora_utc = datetime.datetime.utcnow()
ahora_hora = ahora_utc.hour
# Get day name
dias_semana = [ 'Lunes' , 'Martes' , 'Miércoles' , 'Jueves' , 'Viernes' , 'Sábado' , 'Domingo' ]
dia_nombre = dias_semana[ahora_utc.weekday()]
if ahora_hora < 18 :
mensaje = f "Your Name \n { dia_nombre } \n Entrada - 9:00 AM"
else :
mensaje = f "Your Name \n { dia_nombre } \n Salida - 3:00 PM"
# ... rest of the function
Including Date
Add the current date:
import datetime
def enviar_registro ():
instance_id = os.getenv( 'INSTANCE_ID' )
token = os.getenv( 'TOKEN' )
group_id = os.getenv( 'GROUP_ID' )
ahora_utc = datetime.datetime.utcnow()
ahora_hora = ahora_utc.hour
# Convert to local timezone
offset_horas = - 6
ahora_local = ahora_utc + datetime.timedelta( hours = offset_horas)
fecha_formateada = ahora_local.strftime( " %d /%m/%Y" )
if ahora_hora < 18 :
mensaje = f "Your Name \n Entrada - 9:00 AM \n Fecha: { fecha_formateada } "
else :
mensaje = f "Your Name \n Salida - 3:00 PM \n Fecha: { fecha_formateada } "
# ... rest of the function
Adjusting the Time Threshold
If your schedule changes or you need different logic, modify the threshold:
Flexible Threshold
Timezone-Aware Threshold
Exact Time Matching
# If you have 3+ runs per day
ahora_hora = datetime.datetime.utcnow().hour
if ahora_hora < 16 : # Before 4:00 PM UTC
mensaje = "Your Name \n Entrada - Morning"
elif ahora_hora < 20 : # Between 4:00 PM - 8:00 PM UTC
mensaje = "Your Name \n Regreso de Almuerzo"
else : # After 8:00 PM UTC
mensaje = "Your Name \n Salida - Evening"
WhatsApp Formatting:
*bold text* - Makes text bold
_italic text_ - Makes text italic
~strikethrough~ - Strikes through text
Use emojis for visual appeal: 🟢 for entrada, 🔴 for salida
# With emojis and formatting
if ahora_hora < 18 :
mensaje = "*Your Name* \n 🟢 Entrada \n ⏰ 9:00 AM"
else :
mensaje = "*Your Name* \n 🔴 Salida \n ⏰ 3:00 PM"
# Professional format
if ahora_hora < 18 :
mensaje = "=== REGISTRO DE ASISTENCIA === \n Empleado: Your Name \n Tipo: ENTRADA \n Hora: 9:00 AM \n ==========================="
else :
mensaje = "=== REGISTRO DE ASISTENCIA === \n Empleado: Your Name \n Tipo: SALIDA \n Hora: 3:00 PM \n ==========================="
Testing Your Changes
After modifying the message:
Commit your changes to GitHub
Use the workflow_dispatch trigger to run manually
Check the WhatsApp group for the new message format
Verify the output in GitHub Actions logs
The bot’s response is printed in the workflow logs. Look for: Status: 200, Response: {"sent":"true","message":"ok"}
Complete Example
Here’s a fully customized version with dynamic content:
import requests
import os
import datetime
def enviar_registro ():
instance_id = os.getenv( 'INSTANCE_ID' )
token = os.getenv( 'TOKEN' )
group_id = os.getenv( 'GROUP_ID' )
# Get current time
ahora_utc = datetime.datetime.utcnow()
ahora_hora = ahora_utc.hour
# Convert to local timezone (CST: UTC-6)
offset_horas = - 6
ahora_local = ahora_utc + datetime.timedelta( hours = offset_horas)
hora_formateada = ahora_local.strftime( "%I:%M %p" )
fecha_formateada = ahora_local.strftime( " %d /%m/%Y" )
# Determine message
if ahora_hora < 18 :
tipo = "🟢 ENTRADA"
else :
tipo = "🔴 SALIDA"
mensaje = f "*Your Name* \n { tipo } \n ⏰ { hora_formateada } \n 📅 { fecha_formateada } "
url = f "https://api.ultramsg.com/ { instance_id } /messages/chat"
payload = {
"token" : token,
"to" : group_id,
"body" : mensaje
}
headers = { 'content-type' : 'application/x-www-form-urlencoded' }
r = requests.post(url, data = payload, headers = headers)
print ( f "Status: { r.status_code } , Response: { r.text } " )
if __name__ == "__main__" :
enviar_registro()