Moibe commited on
Commit
0db47cf
路
1 Parent(s): 61f7c93

Round to test Usage Api

Browse files
Files changed (1) hide show
  1. app.py +20 -9
app.py CHANGED
@@ -138,15 +138,26 @@ async def status_callback(request: Request):
138
  # Consultar costo real de uso de WhatsApp del d铆a (cobro por conversaci贸n)
139
  if message_status == 'delivered':
140
  try:
141
- from datetime import date
142
- today = date.today()
143
- usage_records = client.usage.records.today.list(category='whatsapp')
144
- for record in usage_records:
145
- print(f"馃挵 USO WHATSAPP HOY:")
146
- print(f" Categor铆a: {record.category}")
147
- print(f" Cantidad: {record.count}")
148
- print(f" Costo total: {record.price} {record.price_unit}")
149
- print(f" Periodo: {record.start_date} a {record.end_date}")
 
 
 
 
 
 
 
 
 
 
 
150
  except Exception as e:
151
  print(f"鈿狅笍 No se pudo obtener uso de WhatsApp: {str(e)}")
152
 
 
138
  # Consultar costo real de uso de WhatsApp del d铆a (cobro por conversaci贸n)
139
  if message_status == 'delivered':
140
  try:
141
+ whatsapp_categories = [
142
+ 'channels-whatsapp-service',
143
+ 'channels-whatsapp-template-marketing',
144
+ 'channels-whatsapp-template-utility',
145
+ 'channels-whatsapp-template-authentication',
146
+ 'channels-whatsapp-conversation-free',
147
+ 'channels-messaging-inbound',
148
+ 'channels-messaging-outbound',
149
+ ]
150
+ print(f"\n馃挵 USO WHATSAPP HOY:")
151
+ for category in whatsapp_categories:
152
+ try:
153
+ records = client.usage.records.today.list(category=category)
154
+ for record in records:
155
+ if float(record.count) > 0 or float(record.price) > 0:
156
+ print(f" {record.description}:")
157
+ print(f" Cantidad: {record.count} {record.count_unit}")
158
+ print(f" Costo: {record.price} {record.price_unit}")
159
+ except Exception:
160
+ pass
161
  except Exception as e:
162
  print(f"鈿狅笍 No se pudo obtener uso de WhatsApp: {str(e)}")
163