def make_promotions(sender): """ Envia la lista de promociones """ promotions = None responses = list() elements = [] # Mensaje message = Message( text="Esta es la lista de promociones esta semana :)", ) responses.append(Components.typing(responses, sender)) responses.append(MessageRequest(sender, message)) # Componente for promotion in promotions: element = Element( title=promotion.name, item_url=promotion.url, image_url=SERVER_URL + promotion.cover.url, subtitle=promotion.description, buttons=[URLButton(title="VER", url=promotion.url)]) elements.append(element) template = GenericTemplate(elements=elements) attachment = TemplateAttachment(template=template) component = Message(attachment=attachment) responses.append(Components.typing(responses, sender)) responses.append(MessageRequest(sender, component)) return responses
def make_change(sender): responses = list() responses.append(Components.typing(responses, sender)) template = GenericTemplate(elements=[ Element( title="El Dolar Cotiza a 6,929 Bs.", subtitle="1 USD = 6,929 Bs.", default_action=URLButton( url= "https://www.bcb.gob.bo/librerias/indicadores/otras/ultimo.php" ), buttons=[ URLButton( title="VER OTRAS MONEDAS", url= "https://www.bcb.gob.bo/librerias/indicadores/otras/ultimo.php" ) ]) ]) attachment = TemplateAttachment(template=template) component = Message(attachment=attachment) responses.append(Components.typing(responses, sender)) responses.append(MessageRequest(sender, component)) return responses
def insufficient_balance(sender): responses = list() responses.append(Components.typing(responses, sender)) template = GenericTemplate(elements=[ Element( title="Saldo insuficiente para recargar", subtitle="Advertencia", buttons=[ URLButton( title="OTRA RECARGA", url= "https://www.bcb.gob.bo/librerias/indicadores/otras/ultimo.php" ), URLButton( title="CANCELAR", url= "https://www.bcb.gob.bo/librerias/indicadores/otras/ultimo.php" ) ]) ]) attachment = TemplateAttachment(template=template) component = Message(attachment=attachment) responses.append(Components.typing(responses, sender)) responses.append(MessageRequest(sender, component)) return responses
def make_recharge(sender): responses = list() responses.append(Components.typing(responses, sender)) template = GenericTemplate(elements=[ Element( title="Se Recargo con exito 50 Bs al 73053045", subtitle="Gracias por usar el servicio", buttons=[ URLButton( title="INICIO", url= "https://www.bcb.gob.bo/librerias/indicadores/otras/ultimo.php" ), URLButton( title="HACER OTRA RECARGA", url= "https://www.bcb.gob.bo/librerias/indicadores/otras/ultimo.php" ) ]) ]) attachment = TemplateAttachment(template=template) component = Message(attachment=attachment) responses.append(Components.typing(responses, sender)) responses.append(MessageRequest(sender, component)) return responses
def make_own_tickets(sender): # tickets = Ticket.objects.all() tickets = list() responses = list() elements = [] if tickets.count() > 0: # Mensaje message = Message(text="Estos son tus tickets", ) responses.append(Components.typing(responses, sender)) responses.append(MessageRequest(sender, message)) # Componente for ticket in tickets: lat, lng = Components.get_position(ticket.branch) if ticket.type == "CASH": tty = "CAJA" else: tty = "PLATAFORMA" element = Element( title="%s: %s" % (tty, ticket.code), subtitle="%s: %s" % (ticket.branch.bank.name, ticket.branch.name), default_action=URLButton( url=Components.get_map_url(lat, lng) ), buttons=[ PostbackButton( title="CANCELAR", payload="%(payload)s:%(id)s" % { "payload": "CANCEL_TICKET", "id": ticket.id } ), PostbackButton( title="RENOVAR", payload="%(payload)s:%(id)s" % { "payload": "REGENERATE_TICKET", "id": ticket.id } ) ] ) elements.append(element) template = GenericTemplate( elements=elements ) attachment = TemplateAttachment(template=template) component = Message(attachment=attachment) responses.append(Components.typing(responses, sender)) responses.append(MessageRequest(sender, component)) else: message = Message(text="No tienes tickets") responses.append(Components.typing(responses, sender)) responses.append(MessageRequest(sender, message)) return responses
def get_logout_button(sender): template = GenericTemplate( elements=[ Element( title="Cerrar Sesión", image_url="https://goo.gl/Lg2CHu", buttons=[ LogoutButton() ] ) ] ) attachment = TemplateAttachment(template=template) message = Message(attachment=attachment) return MessageRequest(sender, message)
def get_share_button(sender): template = GenericTemplate( elements=[ Element( title="Asi deben saber los humanos", subtitle="Mientras tanto en otro universo", image_url="https://goo.gl/Lg2CHu", buttons=[ ShareButton() ] ) ] ) attachment = TemplateAttachment(template=template) message = Message(attachment=attachment) return MessageRequest(sender, message)
def make_atms(sender): """ Envia la lista de Suscripciones de un usuario o la peticion para registrar una suscripción """ branches = None responses = list() elements = [] if branches.count() > 0: # Mensaje message = Message(text="Esta es la lista de Cajeros cerca :)", ) responses.append(Components.typing(responses, sender)) responses.append(MessageRequest(sender, message)) # Componente for branch in branches: lat, lng = Components.get_position(branch) element = Element( title=branch.name, item_url=Components.get_map_url(lat, lng), image_url=Components.get_map_screen(lat, lng), subtitle=branch.address, buttons=[ PostbackButton( title="VER", payload="%(payload)s:%(id)s" % { "payload": "SELECT_BRANCH", "id": branch.id } ) ] ) elements.append(element) template = GenericTemplate( elements=elements ) attachment = TemplateAttachment(template=template) component = Message(attachment=attachment) responses.append(Components.typing(responses, sender)) responses.append(MessageRequest(sender, component)) else: message = Message(text="No hay cajeros registrados :(") responses.append(Components.typing(responses, sender)) responses.append(MessageRequest(sender, message)) return responses
def get_login_button(sender): template = GenericTemplate( elements=[ Element( title="Iniciar Sesión en Chuspita", image_url="https://goo.gl/Lg2CHu", buttons=[ LoginButton( url="https://oepbolivia.xya/login" ) ] ) ] ) attachment = TemplateAttachment(template=template) message = Message(attachment=attachment) return MessageRequest(sender, message)
def get_generic_template(sender): template = GenericTemplate( elements=[ Element( title="Welcome to Peter\'s Hats", item_url="https://oepbolivia.xyz/", image_url="https://upload.wikimedia.org/wikipedia/en/5/5e/Avatar(Neytiri).jpg", subtitle="Weve got the right hat for everyone.", buttons=[ URLButton( url="https://oepbolivia.xyz/", title="View Website" ), PostbackButton( title="Start Chatting", payload="PAYLOAD" ) ] ), Element( title="HOLA MUNDO", item_url="https://oepbolivia.xyz/", image_url="https://goo.gl/wODF4W", subtitle="Weve got the right hat for everyone.", buttons=[ URLButton( url="https://oepbolivia.xyz/", title="View Website" ), ] ), Element( title="TERCERA PARTE", item_url="https://oepbolivia.xyz/", image_url="https://goo.gl/wODF4W", subtitle="Weve got the right hat for everyone.", ) ] ) attachment = TemplateAttachment(template=template) message = Message(attachment=attachment) return MessageRequest(sender, message)