def perform(self, request: Any) -> bool: if FacebookHelper.send_message(request.sender_id, messages.OPTION1_MESSAGE): buttons = self.build_buttons() FacebookHelper.send_buttons(request.sender_id, messages.QUESTION_TITLE, buttons) Message.objects.create( text=request.text, recipient_id=request.sender_id, sender_id=request.recipient_id )
def perform(self, request: Any) -> bool: if FacebookHelper.send_message(request.sender_id, messages.VIDEO_MESSAGE): elements = [{'media_type': 'video', 'url': 'https://www.facebook.com/Blasfemiiaz/videos/226357831471925/'}] FacebookHelper.send_video(request.sender_id, elements) Message.objects.create( text=request.text, recipient_id=request.sender_id, sender_id=request.recipient_id )
def perform(self, request: Any) -> bool: conversation, created = Conversation.objects.get_or_create( sender_id=request.recipient_id, recipient_id=request.sender_id, ) conversation.status = Conversation.EMAIL conversation.save() if FacebookHelper.send_message(request.sender_id, messages.OPTION3_MESSAGE): FacebookHelper.send_message(request.sender_id, messages.MAIL_MESSAGE) Message.objects.create( text=request.text, recipient_id=request.sender_id, sender_id=request.recipient_id )
def perform(self, request: Any) -> bool: if FacebookHelper.send_message(request.sender_id, messages.CARROUSEL_MESSAGE): #data from a service data = [ {'title': 'Prueba 1', 'subtitle': 'Es una prueba \n de datos en listas', 'image_url': 'https://i.imgur.com/aewqRuV.jpg', 'button_url': 'https://www.lapositiva.com.pe/wps/portal/corporativo/home'}, {'title': 'Prueba 2', 'subtitle': 'Es una prueba \n de datos en listas', 'image_url': 'https://i.imgur.com/aewqRuV.jpg', 'button_url': 'https://www.lapositiva.com.pe/wps/portal/corporativo/home'} ] elements = self.build_elements(data) FacebookHelper.send_carrousel(request.sender_id, elements) Message.objects.create( text=request.text, recipient_id=request.sender_id, sender_id=request.recipient_id )
def perform(self, request: Any) -> None: if FacebookHelper.send_message(request.sender_id, messages.DEFAULT_MESSAGE): Message.objects.create( text=request.text, recipient_id=request.sender_id, sender_id=request.recipient_id )
def perform(self, request: Any) -> bool: if FacebookHelper.send_message(request.sender_id, messages.LIST_MESSAGE): #data from a service data = [ {'title': 'Prueba 1', 'subtitle': 'Es una prueba \n de datos en listas', 'image_url': 'https://i.imgur.com/IGNO7E6.jpg'}, {'title': 'Prueba 2', 'subtitle': 'Es una prueba \n de datos en listas', 'image_url': 'https://i.imgur.com/IGNO7E6.jpg'}, {'title': 'Prueba 3', 'subtitle': 'Es una prueba \n de datos en listas', 'image_url': 'https://i.imgur.com/IGNO7E6.jpg'} ] # elements = self.build_elements(data) FacebookHelper.send_list(request.sender_id, elements) Message.objects.create( text=request.text, recipient_id=request.sender_id, sender_id=request.recipient_id )
def perform(self, request: Any) -> None: conversation, created = Conversation.objects.get_or_create( sender_id=request.recipient_id, recipient_id=request.sender_id, ) try: message = messages.GREETINGS_MESSAGE.replace('Hola!', 'Hola! ' + FacebookGraph().get_user_name(request.sender_id, 'first_name')) if FacebookHelper.send_message(request.sender_id, message): buttons = self.build_buttons() FacebookHelper.send_buttons(request.sender_id, messages.QUESTION_TITLE, buttons) Message.objects.create( text=request.text, recipient_id=request.sender_id, sender_id=request.recipient_id ) except Exception as e: print(sys.stderr, e)
def perform(self, request: Any) -> None: conversation, created = Conversation.objects.get_or_create( sender_id=request.recipient_id, recipient_id=request.sender_id, ) if FacebookHelper.send_message(request.sender_id, messages.GREETINGS_MESSAGE): Message.objects.create(text=request.text, recipient_id=request.sender_id, sender_id=request.recipient_id)
def perform(self, request: Any) -> bool: conversation, created = Conversation.objects.get_or_create( sender_id=request.recipient_id, recipient_id=request.sender_id, ) conversation.status = Conversation.START_STATUS conversation.save() if FacebookHelper.send_message(request.sender_id, messages.MAIL_SUCESS): Message.objects.create( text=request.text, recipient_id=request.sender_id, sender_id=request.recipient_id )
def build_buttons(self) -> List[Any]: post_backs = [ { 'payload': messages.LIST_PAYLOAD, 'title': messages.LIST_TITLE, }, { 'payload': messages.CARROUSEL_PAYLOAD, 'title': messages.CARROUSEL_TITLE, }, ] buttons = [] for post_back in post_backs: buttons.append(FacebookHelper.post_back_button( post_back.get('title'), post_back.get('payload') )) return buttons