Exemplo n.º 1
0
def get_confirmation(item):
    confirm_order = QuickReply(title="✔️ হ্যাঁ",
                               payload=State.CONFIRM_FOOD_ORDER)
    cancel_order = QuickReply(title="❌ না", payload=State.CANCEL_FOOD_ORDER)

    replies = QuickReplies(quick_replies=[confirm_order, cancel_order])

    text = {
        "text":
        f"আইটেম {item['title']} এর দাম পড়বে {item['price']}৳। কনফার্ম করব?"
    }

    text["quick_replies"] = replies.to_dict()

    return text
Exemplo n.º 2
0
    def send_text_with_buttons(self, recipient_id, text, buttons, **kwargs):
        # type: (Text, Text, List[Dict[Text, Any]], Any) -> None
        """Sends buttons to the output."""

        quick_replies = QuickReplies([
            QuickReply(b['title'], b['payload'],
                       b['image_url'] if 'image_url' in b else None, 'text')
            for b in buttons
        ])

        self.send(recipient_id, FBText(text, quick_replies=quick_replies))
Exemplo n.º 3
0
def send_quote_to_user(user_id, quote_text, quote_id):
    actions.mark_quote_as_seen(user_id, quote_id)
    quick_replies = QuickReplies([
        QuickReply(
            content_type="text",
            title='Good one',
            payload=f"like {quote_id}",
        ),
        QuickReply(
            content_type="text",
            title='Not my taste',
            payload=f"dislike {quote_id}",
        ),
    ])
    msg = elements.Text(text=quote_text, quick_replies=quick_replies)
    return messenger.send_msg(msg, user_id)
Exemplo n.º 4
0
    def _convert_to_quick_reply(
            quick_replies: List[Dict[Text, Any]]) -> QuickReplies:
        """Convert quick reply dictionary to FB QuickReplies object"""

        fb_quick_replies = []
        for quick_reply in quick_replies:
            try:
                fb_quick_replies.append(
                    QuickReply(
                        title=quick_reply["title"],
                        payload=quick_reply["payload"],
                        content_type=quick_reply.get("content_type"),
                    ))
            except KeyError as e:
                raise ValueError(
                    'Facebook quick replies must define a "{}" field.'.format(
                        e.args[0]))

        return QuickReplies(quick_replies=fb_quick_replies)
Exemplo n.º 5
0
    def _convert_to_quick_reply(quick_replies: List[Dict[Text, Any]]) -> None:
        """Convert the List[Dict] to a List[QuickReply]
        """
        tmp_quick_replies = []
        for ind, quick_reply in enumerate(quick_replies):
            if "content_type" in quick_reply.keys():
                content_type = quick_reply["content_type"]
            else:
                content_type = "text"
            if "title" and "payload" in quick_reply.keys():
                title = quick_reply["title"]
                payload = quick_reply["payload"]
            else:
                raise ValueError(
                    "You need to specify the title and the payload")
            tmp_quick_replies.append(
                QuickReply(title=title,
                           content_type=content_type,
                           payload=payload))

        quick_replies.clear()
        quick_replies = tmp_quick_replies.copy()
        return QuickReplies(quick_replies=quick_replies)
Exemplo n.º 6
0
def inten_flow(option):
    global quick_replies
    if option == 0:
        quick_reply_1 = QuickReply(title='Go to option 1',
                                   payload='Came to option 1')
        quick_reply_2 = QuickReply(title='Go to option 2',
                                   payload='Came to option 2')
        quick_reply_3 = QuickReply(title='Go to option 3',
                                   payload='Came to option 3')
        quick_replies = QuickReplies(
            quick_replies=[quick_reply_1, quick_reply_2, quick_reply_3])
    if option == 1:
        quick_reply_1 = QuickReply(title='Go back', payload='Back to option 0')
        quick_replies = QuickReplies(quick_replies=[quick_reply_1])
    if option == 2:
        quick_reply_1 = QuickReply(title='Go to option 4',
                                   payload='Came to option 4')
        quick_reply_2 = QuickReply(title='Go to option 6',
                                   payload='Came to option 6')
        quick_reply_3 = QuickReply(title='Go back', payload='Back to option 0')
        quick_replies = QuickReplies(
            quick_replies=[quick_reply_1, quick_reply_2, quick_reply_3])
    if option == 3:
        quick_reply_1 = QuickReply(title='Go to option 5',
                                   payload='Came to option 5')
        quick_reply_2 = QuickReply(title='Go back', payload='Back to option 0')
        quick_replies = QuickReplies(
            quick_replies=[quick_reply_1, quick_reply_2])
    if option == 4:
        quick_reply_1 = QuickReply(title='Go back', payload='Back to option 2')
        quick_replies = QuickReplies(quick_replies=[quick_reply_1])
    if option == 5:
        quick_reply_1 = QuickReply(title='Go back', payload='Back to option 3')
        quick_replies = QuickReplies(quick_replies=[quick_reply_1])
    if option == 6:
        quick_reply_1 = QuickReply(title='Go back', payload='Back to option 2')
        quick_replies = QuickReplies(quick_replies=[quick_reply_1])