예제 #1
0
def make_qrs_set():
    qr1 = quick_replies.QuickReply(title="최신 패치 내역",
                                   payload="PATCH_LIST_PAYLOAD")
    qr2 = quick_replies.QuickReply(title="최신 패치 내역 링크",
                                   payload="PATCH_LINK_PAYLOAD")
    qr3 = quick_replies.QuickReply(title="기능 설명", payload="FUNC_DESC_PAYLOAD")
    return quick_replies.QuickReplies(quick_replies=[qr1, qr2, qr3])
예제 #2
0
def send_start_messages(messenger):
    """Function to launch at the start of restart of the chatbot"""

    txt = _(
        u"🙏🏼 Hi %(first_name)s, so you’ve decided to make your first steps in"
        " Open Source. That’s great.",
        **user
    )
    messenger.send({"text": txt}, "RESPONSE")
    messenger.send_action(typing_on)
    sleep(3)

    # A quick reply to the main menu
    qr1 = quick_replies.QuickReply(
        title=_("✔️ Yes"), payload="KNOW_OS_YES_FULL")
    qr2 = quick_replies.QuickReply(title=_("❌ Not yet"), payload="KNOW_OS_NO")
    qrs = quick_replies.QuickReplies(quick_replies=[qr1, qr2])
    text = {
        "text": _(
            u"So, tell me %(first_name)s do you know what Open Source"
            " is? 👇🏼", **user
        ),
        "quick_replies": qrs.to_dict(),
    }
    messenger.send(text, "RESPONSE")
예제 #3
0
def get_main_menu():
    """Function that return the main menu of the chatbot"""
    open_source = quick_replies.QuickReply(title=_('Open Source 🔓'),
                                           payload='OPEN_SOURCE')
    git = quick_replies.QuickReply(title=_('Git'), payload='GIT_0')
    github = quick_replies.QuickReply(title=_('GitHub'), payload='GITHUB_1')
    fb_os = quick_replies.QuickReply(title=_('FB Open Source'),
                                     payload='FB_OS')
    fork_me = quick_replies.QuickReply(title=_('Fork me on GitHub'),
                                       payload='FORK_ON_GITHUB')

    return quick_replies.QuickReplies(
        quick_replies=[open_source, git, github, fb_os, fork_me])
예제 #4
0
    def message(self, message):
        print('message')
        print(message)                
        get_sender = Text(text= str(message['sender']['id']))
        get_text = Text(text= str(message['message']['text']))
        try:
        	chck_payload = Text(text= str(message['message']['quick_reply']['payload']))
        except KeyError:
        	chck_payload = 'text'
        text = get_text.to_dict()
        text = text['text']
        check = self.read(text, chck_payload)
        print(check)
        # problem hereeeee
        if check != 2:
        	print('check')
        	response = self.movie_route()
        	if self.questions_check[response[0]] == 'quick':
        		print(response)
        		quick_reply = [quick_replies.QuickReply(title=i, payload='quick') for i in response[1]]
        		quick_reply += [quick_replies.QuickReply(title='Go back', payload='quick')]
        		quick_replies_set = quick_replies.QuickReplies(quick_replies=quick_reply)
        		text = { 'text': response[0]}
        		text['quick_replies'] = quick_replies_set.to_dict()
        		self.send(text, 'RESPONSE')
        	else:
        		text = {'text': response[0]}
        		self.send(text, 'RESPONSE')
        		print('carousel')
        		print(self.movies)
        		elems  = []
        		i = 0
        		while i < len(self.movies[0]):
        			btn = elements.Button(title='Read More', payload=movies[2][i], button_type='postback')
        			elem = elements.Element(
        				title=self.movies[2][i],
        				image_url=self.movies[0][i],
        				subtitle=self.movies[1][i],
        				buttons=[
        					btn
        				]
        				)
        			elems.append(elem)
        			i+=1
        		res = templates.GenericTemplate(elements=elems)        		
        		messenger.send(res.to_dict(), 'RESPONSE')
	        	quick_reply = [quick_replies.QuickReply(title='Go back', payload='quick')]
	        	quick_replies_set = quick_replies.QuickReplies(quick_replies=quick_reply)
	        	default = {'quick_replies': quick_replies_set.to_dict()}
	        	self.send(default, 'RESPONSE')
        		print(self.movie_responses['Movies'])
예제 #5
0
파일: main.py 프로젝트: chedabd/felix
def process_message(message):
    app.logger.debug('Message received: {}'.format(message))

    if 'attachments' in message['message']:
        if message['message']['attachments'][0]['type'] == 'location':
            app.logger.debug('Location received')
            response = Text(text='{}: lat: {}, long: {}'.format(
                message['message']['attachments'][0]['title'],
                message['message']['attachments'][0]['payload']['coordinates']
                ['lat'], message['message']['attachments'][0]['payload']
                ['coordinates']['long']))
            return response.to_dict()

    if 'text' in message['message']:
        msg = message['message']['text'].lower()
        response = Text(text='Sorry didn\'t understand that: {}'.format(msg))
        if 'text' in msg:
            response = Text(text='This is an example text message.')
        if 'image' in msg:
            response = Image(url='https://unsplash.it/300/200/?random')
        if 'video' in msg:
            response = Video(
                url='http://techslides.com/demos/sample-videos/small.mp4')
        if 'quick replies' in msg:
            qr1 = quick_replies.QuickReply(title='Location',
                                           content_type='location')
            qr2 = quick_replies.QuickReply(title='Payload',
                                           payload='QUICK_REPLY_PAYLOAD')
            qrs = quick_replies.QuickReplies(quick_replies=[qr1, qr2])
            response = Text(text='This is an example text message.',
                            quick_replies=qrs)
        if 'payload' in msg:
            txt = 'User clicked {}, button payload is {}'.format(
                msg, message['message']['quick_reply']['payload'])
            response = Text(text=txt)
        if 'webview-compact' in msg:
            btn = get_button(ratio='compact')
            elem = get_element(btn)
            response = GenericTemplate(elements=[elem])
        if 'webview-tall' in msg:
            btn = get_button(ratio='tall')
            elem = get_element(btn)
            response = GenericTemplate(elements=[elem])
        if 'webview-full' in msg:
            btn = get_button(ratio='full')
            elem = get_element(btn)
            response = GenericTemplate(elements=[elem])

        return response.to_dict()
예제 #6
0
    def test_quick_replies(self):
        qr = quick_replies.QuickReply(title='QR', payload='QR payload')
        qrs = quick_replies.QuickReplies(quick_replies=[qr] * 2)

        res = attachments.Image(url='http://facebook.com/image.jpg',
                                quick_replies=qrs)
        expected = {
            'attachment': {
                'type': 'image',
                'payload': {
                    'url': 'http://facebook.com/image.jpg'
                },
            },
            'quick_replies': [
                {
                    'content_type': 'text',
                    'title': 'QR',
                    'payload': 'QR payload'
                },
                {
                    'content_type': 'text',
                    'title': 'QR',
                    'payload': 'QR payload'
                },
            ],
        }
        assert expected == res.to_dict()
예제 #7
0
def dishes_to_quick_reply(dishes):
    replies = []
    payload = dishes_to_payload(dishes)
    for dish in dishes:
        # we can only send max 11 quick reply buttons to facebook
        if len(replies) > 10:
            break

        # dish is a dictionary when we get the informations from the database
        if type(dish) is dict:
            replies.append(quick_replies.QuickReply(title=dish["ko_name"]+"("+dish["name"]+")", payload=payload))
        # and a string when we get it from the payload of a facebook quick reply
        else:
            replies.append(quick_replies.QuickReply(title=dish, payload=payload))

    return quick_replies.QuickReplies(quick_replies=replies)
예제 #8
0
def test_upload_no_quick_replies(client):
    replies = quick_replies.QuickReplies(
        [quick_replies.QuickReply(title='hello', payload='hello')])
    attachment = attachments.Image(url='https://some-image.com/image.jpg',
                                   quick_replies=replies)
    with pytest.raises(ValueError):
        client.upload_attachment(attachment)
예제 #9
0
 def test_quick_reply_title_too_long(self, caplog):
     with caplog.at_level(logging.WARNING, logger='fbmessenger.elements'):
         quick_replies.QuickReply(title='Title is over the 20 character limit',
                                        payload='QR payload')
         assert caplog.record_tuples == [
             ('fbmessenger.quick_replies', logging.WARNING,
               CHARACTER_LIMIT_MESSAGE.format(field='Title', maxsize=20))]
예제 #10
0
def process_quick_rpls(quick_rpls):
    """Takes n number of quick_replies and returns them processed"""

    q_rpls_list = []
    for q_r in quick_rpls:
        q_rpls_list.append(quick_replies.QuickReply(title=q_r, payload=q_r))
    return quick_replies.QuickReplies(quick_replies=q_rpls_list)
예제 #11
0
 def test_generic_template_with_quick_replies(self):
     btn = elements.Button(
         button_type='web_url',
         title='Web button',
         url='http://facebook.com'
     )
     elems = elements.Element(
         title='Element',
         item_url='http://facebook.com',
         image_url='http://facebook.com/image.jpg',
         subtitle='Subtitle',
         buttons=[
             btn
         ]
     )
     qr = quick_replies.QuickReply(title='QR', payload='QR payload')
     qrs = quick_replies.QuickReplies(quick_replies=[qr] * 2)
     res = templates.GenericTemplate(
         elements=[elems],
         quick_replies=qrs
     )
     expected = {
         'attachment': {
             'type': 'template',
             'payload': {
                 'template_type': 'generic',
                 'sharable': False,
                 'elements': [
                     {
                         'title': 'Element',
                         'item_url': 'http://facebook.com',
                         'image_url': 'http://facebook.com/image.jpg',
                         'subtitle': 'Subtitle',
                         'buttons': [
                             {
                                 'type': 'web_url',
                                 'title': 'Web button',
                                 'url': 'http://facebook.com'
                             }
                         ]
                     }
                 ],
             },
         },
         'quick_replies': [
             {
                 'content_type': 'text',
                 'title': 'QR',
                 'payload': 'QR payload'
             },
             {
                 'content_type': 'text',
                 'title': 'QR',
                 'payload': 'QR payload'
             },
         ],
     }
     assert expected == res.to_dict()
예제 #12
0
 def postback(self, message):
 	print('postback')
 	try:
 		payload = message['postback']['payload']
 	except Exception as e:
 		payload = message
 	if 'start' in payload:
 		text = { 'text': 'Welcome to InstaTickets'}
 		self.send(text, 'RESPONSE')
 		quick_reply_1 = quick_replies.QuickReply(title='Movie Tickets', payload='first')
 		quick_reply_2 = quick_replies.QuickReply(title='Event Tickets', payload='first')
 		quick_reply_3 = quick_replies.QuickReply(title='Quit', payload='quit')
 		quick_replies_set = quick_replies.QuickReplies(quick_replies=[
 			quick_reply_1,
 			quick_reply_2,
 			quick_reply_3
 			])
 		text = { 'text': 'What ticket do you want to buy?'}
 		text['quick_replies'] = quick_replies_set.to_dict()
 		self.send(text, 'RESPONSE')
 	else:
 		quick_reply_1 = quick_replies.QuickReply(title='Movie Tickets', payload='movie')
 		quick_reply_2 = quick_replies.QuickReply(title='Event Tickets', payload='event')
 		quick_reply_3 = quick_replies.QuickReply(title='Quit', payload='quit')
 		quick_replies_set = quick_replies.QuickReplies(quick_replies=[
 			quick_reply_1,
 			quick_reply_2,
 			quick_reply_3
 			])
 		text = { 'text': 'What ticket do you want to buy?'}
 		text['quick_replies'] = quick_replies_set.to_dict()
 		self.send(text, 'RESPONSE')    		
예제 #13
0
 def test_quick_reply(self):
     res = quick_replies.QuickReply(
         title='QR',
         payload='QR payload',
         image_url='QR image',
     )
     expected = {
         'content_type': 'text',
         'title': 'QR',
         'payload': 'QR payload',
         'image_url': 'QR image'
     }
     assert expected == res.to_dict()
예제 #14
0
def send_start_messages(messenger):
    """Function to launch at the start of restart of the chatbot"""

    txt = _(
        u'🙏🏼 Hi %(first_name)s, so you’ve decided to make your first steps in'
        ' Open Source. That’s great.', **user)
    messenger.send({'text': txt}, 'RESPONSE')
    messenger.send_action(typing_on)
    sleep(3)

    # A quick reply to the main menu
    qr1 = quick_replies.QuickReply(title=_('✔️ Yes'),
                                   payload='KNOW_OS_YES_FULL')
    qr2 = quick_replies.QuickReply(title=_('❌ Not yet'), payload='KNOW_OS_NO')
    qrs = quick_replies.QuickReplies(quick_replies=[qr1, qr2])
    text = {
        "text":
        _(u'So tell me %(first_name)s do you know what Open Source'
          ' is? 👇🏼', **user),
        "quick_replies":
        qrs.to_dict()
    }
    messenger.send(text, 'RESPONSE')
예제 #15
0
 def test_quick_replies(self):
     qr = quick_replies.QuickReply(title='QR', payload='QR payload')
     qrs = quick_replies.QuickReplies(quick_replies=[qr] * 2)
     expected = [
         {
             'content_type': 'text',
             'title': 'QR',
             'payload': 'QR payload'
         },
         {
             'content_type': 'text',
             'title': 'QR',
             'payload': 'QR payload'
         }
     ]
     assert expected == qrs.to_dict()
예제 #16
0
    def test_text_with_quick_replies(self):
        qr = quick_replies.QuickReply(title='QR', payload='QR payload')
        qrs = quick_replies.QuickReplies(quick_replies=[qr] * 2)

        res = elements.Text(text='Test Message', quick_replies=qrs)
        expected = {
            'text':
            'Test Message',
            'quick_replies': [{
                'content_type': 'text',
                'title': 'QR',
                'payload': 'QR payload'
            }, {
                'content_type': 'text',
                'title': 'QR',
                'payload': 'QR payload'
            }]
        }
        assert expected == res.to_dict()
예제 #17
0
def get_main_menu():
    """Function that returns the main menu of the chatbot"""
    open_source = quick_replies.QuickReply(title=_("Open Source 🔓"),
                                           payload="OPEN_SOURCE")
    git = quick_replies.QuickReply(title=_("Git"), payload="GIT_0")
    github = quick_replies.QuickReply(title=_("GitHub"), payload="GITHUB_1")
    contr = quick_replies.QuickReply(title=_("Make a PR"), payload="CONTR_1")
    fb_os = quick_replies.QuickReply(title=_("FB Open Source"),
                                     payload="FB_OS")
    fork_me = quick_replies.QuickReply(title=_("Fork me on GitHub"),
                                       payload="FORK_ON_GITHUB")

    return quick_replies.QuickReplies(
        quick_replies=[open_source, git, github, contr, fb_os, fork_me])
예제 #18
0
 def test_dynamic_text_with_quick_replies(self):
     qr = quick_replies.QuickReply(title='QR', payload='QR payload')
     qrs = quick_replies.QuickReplies(quick_replies=[qr])
     res = elements.DynamicText('Hi, {{first_name}}!',
                                'Hello friend!',
                                quick_replies=qrs)
     expected = {
         'dynamic_text': {
             'text': 'Hi, {{first_name}}!',
             'fallback_text': 'Hello friend!',
         },
         'quick_replies': [
             {
                 'content_type': 'text',
                 'title': 'QR',
                 'payload': 'QR payload'
             },
         ],
     }
     assert expected == res.to_dict()
예제 #19
0
 def onMessage(self, author_id, message_object, thread_id, thread_type,
               **kwargs):
     self.markAsDelivered(thread_id, message_object.uid)
     self.markAsRead(thread_id)
     print(type(thread_id))
     print(type(thread_type))
     log.info("{} from {} in {}".format(message_object, thread_id,
                                        thread_type.name))
     # If you're not the author, echo
     if author_id != self.uid:
         quick_reply_1 = quick_replies.QuickReply(title='Location',
                                                  content_type='location')
         quick_replies_set = quick_replies.QuickReplies(
             quick_replies=[quick_reply_1])
         text = {'text': 'Share your location'}
         text['quick_replies'] = quick_replies_set.to_dict()
         quick_replies = [
             QuickReply(title="Action", payload="PICK_ACTION"),
             QuickReply(title="Comedy", payload="PICK_COMEDY")
         ]
         self.send(Message(text=text),
                   thread_id=thread_id,
                   thread_type=thread_type)
예제 #20
0
def process_postback(messenger, payload):
    """Function to process postbacks

    Args:
        messenger ([Messenger]): a Messenger Object
        payload ([Payload]): the payload sent by the user
    """
    init_user_preference(messenger)

    if "START" in payload:
        send_start_messages(messenger)
        return True

    if "MAIN_MENU" in payload:
        text = {
            "text": _(u"This is the main menu, select what you need below 👇🏼"),
            "quick_replies": get_main_menu().to_dict(),
        }
        messenger.send(text, "RESPONSE")
        return True

    if "OPEN_SOURCE" in payload:
        qr1 = quick_replies.QuickReply(title=_("✔️ Yes"),
                                       payload="KNOW_OS_YES_FULL")
        qr2 = quick_replies.QuickReply(title=_("❌ Not yet"),
                                       payload="KNOW_OS_NO")
        qrs = quick_replies.QuickReplies(quick_replies=[qr1, qr2])
        text = {
            "text":
            _(
                u"So, tell me %(first_name)s do you know what Open source"
                " is? 👇🏼", **user),
            "quick_replies":
            qrs.to_dict(),
        }
        messenger.send(text, "RESPONSE")
        return True

    if payload.startswith("KNOW_OS_YES"):
        if "KNOW_OS_YES_FULL" in payload:
            messenger.send({"text": _(u"Amazing!")}, "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)

        qr1 = quick_replies.QuickReply(title=_("✔️ Yes"), payload="CVS_YES")
        qr2 = quick_replies.QuickReply(title=_("❌ Not yet"), payload="CVS_NO")
        qrs = quick_replies.QuickReplies(quick_replies=[qr1, qr2])
        text = {
            "text":
            _(u"An important component in Open Source contribution is"
              " version control tools. Are you familiar with the concept of"
              " version control? 👇🏼"),
            "quick_replies":
            qrs.to_dict(),
        }
        messenger.send(text, "RESPONSE")
        return True

    if "KNOW_OS_NO" in payload:
        text = _(
            u"According to the dictionary, Open-source 🔓 software, denotes"
            " software for which the original source code is made freely 🆓"
            " available and may be redistributed and modified"
            " according to the requirement of the user 👨‍💻.")
        messenger.send({"text": text}, "RESPONSE")
        messenger.send_action(typing_on)
        sleep(3)

        qr = quick_replies.QuickReply(title=_("👉🏽 Next"),
                                      payload="KNOW_OS_YES")
        qrs = quick_replies.QuickReplies(quick_replies=[qr])
        text = {
            "text":
            _(u'👩🏽‍🏫 You know ...\n✔️ Wordpress,\n✔️ Notepad++,\n✔️ Ubuntu\n'
              'and thousands of common software started out as Open-source'
              ' software? 👇🏼'),
            "quick_replies":
            qrs.to_dict(),
        }
        messenger.send(text, "RESPONSE")
        return True

    if "CVS_NO" in payload:
        text = {
            "text":
            _(u"😎 Worry not!\n\n"
              "Version control allows you to manage changes to files over"
              " time ⏱️ so that you can recall specific versions later.")
        }
        messenger.send(text, "RESPONSE")
        messenger.send_action(typing_on)
        sleep(3)
        text = {
            "text":
            _(u"You can use version control to version code, binary files,"
              " and digital assets 🗄️.")
        }
        messenger.send(text, "RESPONSE")
        messenger.send_action(typing_on)
        sleep(3)
        text = {
            "text":
            _(u"This includes version control software, version control"
              " systems, or version control tools 🧰.")
        }
        messenger.send(text, "RESPONSE")
        messenger.send_action(typing_on)
        sleep(3)
        text = {
            "text":
            _(u"Version control is a component of software configuration"
              " management 🖥️.")
        }
        messenger.send(text, "RESPONSE")
        messenger.send_action(typing_on)
        sleep(3)
        qr = quick_replies.QuickReply(title=_("👉🏽 Next"), payload="CVS_YES")
        qrs = quick_replies.QuickReplies(quick_replies=[qr])
        text = {
            "text":
            _(u"😎 Now that you understand what Version control is,"
              " let's explore another important topic."),
            "quick_replies":
            qrs.to_dict(),
        }
        messenger.send(text, "RESPONSE")
        return True

    if "CVS_YES" in payload:
        qr1 = quick_replies.QuickReply(title=_("What is Git❔"),
                                       payload="GIT_1")
        qr2 = quick_replies.QuickReply(title=_("What is GitHub❔"),
                                       payload="GITHUB_1")
        qrs = quick_replies.QuickReplies(quick_replies=[qr1, qr2])
        text = {
            "text": _(u"What do you want to start with⁉️ 👇🏼"),
            "quick_replies": qrs.to_dict(),
        }
        messenger.send(text, "RESPONSE")
        return True

    if "GITHUB_1" in payload:
        qr = quick_replies.QuickReply(title=_("👉🏽 Next"), payload="GITHUB_2")
        qrs = quick_replies.QuickReplies(quick_replies=[qr])
        text = {
            "text":
            _(u"GitHub is a code hosting platform for version control and"
              " collaboration. It lets you and others work together on"
              " projects from anywhere."),
            "quick_replies":
            qrs.to_dict(),
        }
        messenger.send(text, "RESPONSE")
        return True

    if "GITHUB_2" in payload:
        btn1 = Button(button_type="web_url",
                      title=_("Official Website"),
                      url="https://github.com")
        btn2 = Button(
            button_type="web_url",
            title=_("GitHub Tutorial"),
            url="https://guides.github.com/activities/hello-world/",
        )
        btn3 = Button(button_type="postback",
                      title=_("👩‍💻 Make a PR"),
                      payload="CONTR_1")
        app_url = os.environ.get("APP_URL", "localhost")
        elems = Element(
            title=_(u"Discover GitHub"),
            image_url=app_url + "/static/img/github.jpg",
            subtitle=_(
                u"Discover GitHub official website, or follow a beginner"
                " tutorial", ),
            # Messenger only accepts 3 buttons, hard choice to make!
            buttons=[btn1, btn2, btn3],
        )
        res = GenericTemplate(elements=[elems])
        logger.debug(res.to_dict())
        messenger.send(res.to_dict(), "RESPONSE")
        return True

    if payload.startswith("GIT_"):
        if "GIT_1" in payload:
            messenger.send({"text": _("Good question 👌🏽")}, "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)

            text = _(
                u"Git is a type of version control system (VCS) that makes"
                " it easier to track changes to files. ")
            messenger.send({"text": text}, "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)

            text = _(
                u"For example, when you edit a file, Git can help you"
                " determine exactly what changed, who changed it, and why.")
            messenger.send({"text": text}, "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)

            qr1 = quick_replies.QuickReply(title=_("👶🏽 Install Git"),
                                           payload="INSTALL_GIT")
            qr2 = quick_replies.QuickReply(title=_("🤓 I've Git Installed"),
                                           payload="CONF_GIT")
            qrs = quick_replies.QuickReplies(quick_replies=[qr1, qr2])
            text = {
                "text": _(u"Want to learn more about Git?"),
                "quick_replies": qrs.to_dict(),
            }
            messenger.send(text, "RESPONSE")
            return True

    ###################################
    # FIRST TIME CONTRIBUTION SECTION #
    ###################################
    # Guiding users to this first time contribution
    if payload.startswith("CONTR_"):

        if "CONTR_1" in payload:
            messenger.send({"text": _("Good decision 👌🏽")}, "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)

            text = _(u"We are going to split the process into 5 steps: \n"
                     "🛵 Fork, Clone, Update, Push and Merge. ")
            messenger.send({"text": text}, "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)

            qr = quick_replies.QuickReply(title=_("🥢 1. Fork"),
                                          payload="CONTR_2")
            qrs = quick_replies.QuickReplies(quick_replies=[qr])
            text = {
                "text": _(u"Ready for the first step?!"),
                "quick_replies": qrs.to_dict(),
            }
            messenger.send(text, "RESPONSE")
            return True

        # Fork Step
        if "CONTR_2" in payload:
            messenger.send({"text": _("Awesome 👌🏽")}, "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)

            text = _(
                u"Open this link in a new window: \n"
                "https://github.com/fbdevelopercircles/open-source-edu-bot")
            messenger.send({"text": text}, "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)
            text = _(
                u"Now, click `Fork` on the top right corner of your screen")
            messenger.send({"text": text}, "RESPONSE")
            image = Image(
                url="https://docs.github.com/assets/images/help/repository/"
                "fork_button.jpg")
            messenger.send(image.to_dict(), "RESPONSE")
            messenger.send_action(typing_on)
            text = _(u"A copy of the original project will be created in your"
                     " account.")
            messenger.send({"text": text}, "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)
            qr = quick_replies.QuickReply(title=_("🚃 2. Clone"),
                                          payload="CONTR_3_1")
            qrs = quick_replies.QuickReplies(quick_replies=[qr])
            text = {
                "text": _(u"Ready for the next step?!"),
                "quick_replies": qrs.to_dict(),
            }
            messenger.send(text, "RESPONSE")
            return True

        # Clone Step
        if "CONTR_3_1" in payload:
            messenger.send({"text": _("Great 👌🏽")}, "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)

            text = _(
                u"Right now, you have a fork of the `open-source-edu-bot`"
                " repository, but you don't have the files in that repository"
                " on your computer.")
            messenger.send({"text": text}, "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)
            text = _(
                u"Let's create a clone of your fork locally on your computer."
                "\nOn GitHub, in your newly forked project, Click on `Code`"
                " above the list of files")
            messenger.send({"text": text}, "RESPONSE")
            image = Image(
                url="https://docs.github.com/assets/images/help/repository/"
                "code-button.png")
            messenger.send(image.to_dict(), "RESPONSE")

            qr = quick_replies.QuickReply(title=_("👉🏽 Next"),
                                          payload="CONTR_3_2")
            qrs = quick_replies.QuickReplies(quick_replies=[qr])
            text = {
                "text": _(u"When you feel Ready🔥, hit Next to continue."),
                "quick_replies": qrs.to_dict(),
            }
            messenger.send(text, "RESPONSE")
            return True
        if "CONTR_3_2" in payload:
            text = _(
                u'To clone the repository using HTTPS, under'
                ' "Clone with HTTPS", click copy icon.\n'
                'To clone the repository using an SSH key click "Use SSH", '
                'then click on copy icon.')
            messenger.send({"text": text}, "RESPONSE")
            image = Image(url="https://docs.github.com/assets/"
                          "images/help/repository/https-url-clone.png")
            messenger.send(image.to_dict(), "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)
            text = _(
                u"Now open a terminal, change the current working directory"
                " to the location where you want the cloned directory.")
            messenger.send({"text": text}, "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)
            text = _(
                u"Type `git clone`, and then paste the URL you copied "
                "earlier.\nPress Enter. Your local clone will be created.")
            messenger.send({"text": text}, "RESPONSE")
            messenger.send_action(typing_on)
            qr = quick_replies.QuickReply(title=_("🥯 3. Update"),
                                          payload="CONTR_4")
            qrs = quick_replies.QuickReplies(quick_replies=[qr])
            text = {
                "text":
                _(u"Now, you have a local copy of the project, Let's update"
                  " it!"),
                "quick_replies":
                qrs.to_dict(),
            }
            messenger.send(text, "RESPONSE")
            return True

        # Update Step
        if "CONTR_4" in payload:
            messenger.send({"text": _("Amazing 👌🏽")}, "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)

            text = _(u"Open the project using your favorite IDE, and look for"
                     " `contributors.yaml` file")
            messenger.send({"text": text}, "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)
            text = _(u"This Yaml file contains list of project contributors,"
                     " just like you.")
            messenger.send({"text": text}, "RESPONSE")
            messenger.send_action(typing_on)
            image = Image(
                url="https://media.giphy.com/media/UsBYak2l75W5VheVPF/"
                "giphy.gif")
            messenger.send(image.to_dict(), "RESPONSE")
            text = _(
                u"Following the same scheme, add your name, country and github"
                " username to the list.")
            messenger.send({"text": text}, "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)
            qr = quick_replies.QuickReply(title=_("🚲 4. Push"),
                                          payload="CONTR_5")
            qrs = quick_replies.QuickReplies(quick_replies=[qr])
            text = {
                "text": _(u"Ready to commit & Push your changes?!"),
                "quick_replies": qrs.to_dict(),
            }
            messenger.send(text, "RESPONSE")
            return True

        # Push Step
        if "CONTR_5" in payload:
            messenger.send({"text": _("Way to go 👌🏽")}, "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)
            text = _(
                u"Open your Terminal.\nChange the current working directory"
                " to your local repository."
                "\nStage the file by commiting it to your"
                " local repository using: `git add .`")
            messenger.send({"text": text}, "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)
            text = _(u'Commit the file that you\'ve staged in your local'
                     ' repository:\n'
                     '`git commit -m "Add YOUR_NAME to contributors list"`\n'
                     "Make sure to add your name :D")
            messenger.send({"text": text}, "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)
            text = _(u"Finally, Push the changes in your local repository to "
                     " GitHub: `git push origin master`")
            messenger.send({"text": text}, "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)
            qr = quick_replies.QuickReply(title=_("🔐 5. Merge"),
                                          payload="CONTR_6")
            qrs = quick_replies.QuickReplies(quick_replies=[qr])
            text = {
                "text": _(u"Ready to make your first PR?!"),
                "quick_replies": qrs.to_dict(),
            }
            messenger.send(text, "RESPONSE")
            return True

        # Merge Step
        if "CONTR_6" in payload:
            messenger.send({"text": _("Proud of you 👌🏽")}, "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)
            text = _(
                u"Now go back to the original repo:"
                " https://github.com/fbdevelopercircles/open-source-edu-bot \n"
                "Above the list of files, click `Pull request`.")
            messenger.send({"text": text}, "RESPONSE")
            primg = Image(url="https://docs.github.com/assets/images/help/"
                          "pull_requests/pull-request-start-review-button.png")
            messenger.send(primg.to_dict(), "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)
            text = _(
                u'Make sure that "base branch" & "head fork" drop-down menus'
                ' both are pointing to `master`.')
            messenger.send({"text": text}, "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)
            prdesc = Image(url="https://docs.github.com/assets/images/help/"
                           "pull_requests/pullrequest-description.png")
            messenger.send(prdesc.to_dict(), "RESPONSE")
            text = _(u"Type a title and description for your pull request."
                     " Then click `Create Pull Request`.")
            messenger.send({"text": text}, "RESPONSE")
            messenger.send_action(typing_on)
            qr = quick_replies.QuickReply(title=_("✅ Done"), payload="CONTR_7")
            qrs = quick_replies.QuickReplies(quick_replies=[qr])
            text = {
                "text": _(u"Have you created your first PR?"),
                "quick_replies": qrs.to_dict(),
            }
            messenger.send(text, "RESPONSE")
            return True

        # Merge Step
        if "CONTR_7" in payload:
            messenger.send({"text": _("🙌🎉 Bravo %(first_name)s 🙌🎉", **user)},
                           "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)
            response = Image(
                url="https://media.giphy.com/media/MOWPkhRAUbR7i/giphy.gif")
            messenger.send(response.to_dict(), "RESPONSE")
            messenger.send(
                {
                    "text":
                    _("Now the team will review your PR and merge it ASAP :D")
                },
                "RESPONSE",
            )
            messenger.send_action(typing_on)
            sleep(3)
            text = {
                "text":
                _(u"Given below are other interesting stuff"
                  " that we can explore together:"),
                "quick_replies":
                get_main_menu().to_dict(),
            }
            messenger.send(text, "RESPONSE")
            return True

    if payload.startswith("GIT_"):
        if "GIT_1" in payload:
            messenger.send({"text": _("Good question 👌🏽")}, "RESPONSE")
            messenger.send_action(typing_on)
            sleep(3)

        text = _(u"Git is a type of version control system (VCS) that makes it"
                 " easier to track changes to files. ")
        messenger.send({"text": text}, "RESPONSE")
        messenger.send_action(typing_on)
        sleep(3)

        text = _(
            u"For example, when you edit a file, Git can help you determine"
            " exactly what changed, who changed it, and why.")
        messenger.send({"text": text}, "RESPONSE")
        messenger.send_action(typing_on)
        sleep(3)

        qr1 = quick_replies.QuickReply(title=_("👶🏽 Install Git"),
                                       payload="INSTALL_GIT")
        qr2 = quick_replies.QuickReply(title=_("🤓 I've Git Installed"),
                                       payload="CONF_GIT")
        qrs = quick_replies.QuickReplies(quick_replies=[qr1, qr2])
        text = {
            "text": _(u"Want to learn more about Git?"),
            "quick_replies": qrs.to_dict(),
        }
        messenger.send(text, "RESPONSE")
        return True

    if "INSTALL_GIT" in payload:

        text = _(u"Time to get Git installed in your machine ⭕!")
        messenger.send({"text": text}, "RESPONSE")
        messenger.send_action(typing_on)
        sleep(3)
        btn = Button(
            button_type="web_url",
            title=_("Download Git"),
            url="https://git-scm.com/downloads",
        )
        elems = Element(
            title=_(u"Head over here, and download Git"
                    " Client based on your OS."),
            buttons=[btn],
        )
        res = GenericTemplate(elements=[elems])
        logger.debug(res.to_dict())
        messenger.send(res.to_dict(), "RESPONSE")
        messenger.send_action(typing_on)
        sleep(3)
        qr2 = quick_replies.QuickReply(title=_("Configure Git ⚒️"),
                                       payload="CONF_GIT")
        qrs = quick_replies.QuickReplies(quick_replies=[qr2])
        text = {
            "text": _(u"🧑‍🚀 Once done, let's configure Git"),
            "quick_replies": qrs.to_dict(),
        }
        messenger.send(text, "RESPONSE")
        return True

    if "CONF_GIT" in payload:

        text = _(u"Great Progress so far 👨🏽‍🎓!")
        messenger.send({"text": text}, "RESPONSE")
        messenger.send_action(typing_on)
        sleep(2)
        text = _(u"Now let's configure your Git username and email using the"
                 " following commands")
        messenger.send({"text": text}, "RESPONSE")
        messenger.send_action(typing_on)
        sleep(2)
        text = _(u'`$ git config --global user.name "Steve Josh"`')
        messenger.send({"text": text}, "RESPONSE")
        messenger.send_action(typing_on)
        sleep(2)
        text = _(u'`$ git config --global user.email "*****@*****.**"`')
        messenger.send({"text": text}, "RESPONSE")
        messenger.send_action(typing_on)
        sleep(2)
        text = _(
            u"Don't forget to replace Steve's  name and email with your own.")
        messenger.send({"text": text}, "RESPONSE")
        messenger.send_action(typing_on)
        sleep(2)
        text = _(u"These details will be associated with any commits that you"
                 " create")
        messenger.send({"text": text}, "RESPONSE")
        messenger.send_action(typing_on)
        sleep(2)
        qr = quick_replies.QuickReply(title=_("GitHub"), payload="GITHUB_1")
        qrs = quick_replies.QuickReplies(quick_replies=[qr])
        text = {
            "text": _(u"Now let's check, what is Github?👇🏼"),
            "quick_replies": qrs.to_dict(),
        }
        messenger.send(text, "RESPONSE")
        return True

    if "FB_OS" in payload:
        text = _(u"Facebook 🧡 Open Source!")
        messenger.send({"text": text}, "RESPONSE")
        sleep(3)

        text = _(u"Facebook manages many Open Source projects in the following"
                 " areas:\n"
                 "✔️ Android\n"
                 "✔️ Artificial Intelligence\n"
                 "✔️ Data Infrastructure\n"
                 "✔️ Developer Operations\n"
                 "✔️ Development Tools\n"
                 "✔️ Frontend\n"
                 "✔️ iOS\n"
                 "✔️ Languages\n"
                 "✔️ Linux\n"
                 "✔️ Security\n"
                 "✔️ Virtual Reality\n"
                 "...")
        messenger.send({"text": text}, "RESPONSE")
        sleep(3)

        btn = Button(
            button_type="web_url",
            title=_("Explore them"),
            url="https://opensource.facebook.com/projects",
        )
        elems = Element(title=_(u"Explore Facebook Open Source projects"),
                        buttons=[btn])
        res = GenericTemplate(elements=[elems])
        logger.debug(res.to_dict())
        messenger.send(res.to_dict(), "RESPONSE")

        return True

    if "FORK_ON_GITHUB" in payload:
        text = _(u"🤓 You know what? This chatbot code is Open Source 🔓, it's"
                 " developed by Facebook Developers Circles members around the"
                 " world.")
        messenger.send({"text": text}, "RESPONSE")
        sleep(5)

        text = _(
            u"%(first_name)s we welcome contributors, or simply feel free to"
            " fork the code on GitHub, and create your own chatbot.", **user)
        messenger.send({"text": text}, "RESPONSE")
        sleep(5)

        btn1 = Button(
            button_type="web_url",
            title=_("The Source Code"),
            url="https://github.com/fbdevelopercircles/open-source-edu-bot",
        )
        btn2 = Button(
            button_type="web_url",
            title=_("Join a circle"),
            url="https://developers.facebook.com/developercircles",
        )
        btn3 = Button(button_type="postback",
                      title=_("🚶🏽‍♀️ Main Menu 🗄️"),
                      payload="MAIN_MENU")
        elems = Element(title=_(u"Select an option 👇🏼"),
                        buttons=[btn1, btn2, btn3])
        res = GenericTemplate(elements=[elems])
        logger.debug(res.to_dict())
        messenger.send(res.to_dict(), "RESPONSE")

        return True

    # the default action
    qr = quick_replies.QuickReply(title=_("🚶🏽‍♀️ Main Menu 🗄️"),
                                  payload="MAIN_MENU")
    qrs = quick_replies.QuickReplies(quick_replies=[qr])
    text = {"text": _(u"Coming soon!"), "quick_replies": qrs.to_dict()}
    messenger.send(text, "RESPONSE")
    return False
예제 #21
0
파일: app.py 프로젝트: enod/road-issue-bot
    def message(self, message):
        app.logger.debug(message)
        global dialogue
        if 'text' in message['message']:
            msg = message['message']['text'].lower()
            if len(dialogue) == 6:
                dialogue = set()

            # Greetings
            if msg in [
                    "hi", "hi there", "hello", "sain bainuu", "сайн уу", "hey",
                    "yo"
            ]:
                user_info = self.get_user()
                response = Image(
                    url='https://i.ytimg.com/vi/penG2V8bMBE/maxresdefault.jpg')
                self.send(response.to_dict(), 'RESPONSE')
                response = Text(
                    text=
                    'Hello {}! I’m SMART CITY chatbot 🤖, I can offer you municipality service everywhere at any time. You can message me about road issues. '
                    .format(user_info['first_name']))
                self.send(response.to_dict(), 'RESPONSE')
                qr1 = quick_replies.QuickReply(title='Open issue',
                                               payload='open_issue')
                qr2 = quick_replies.QuickReply(title='Live city',
                                               payload='live_city')
                qrs = quick_replies.QuickReplies(quick_replies=[qr1, qr2])
                response = Text(text='How can I help you today?',
                                quick_replies=qrs)
                self.send(response.to_dict(), 'RESPONSE')
                dialogue.add('Greetings')

            # Phone number
            if dialogue == {'Greetings', 'Name'}:
                response = Text(text='Please enter your phone number:')
                self.send(response.to_dict(), 'RESPONSE')
                dialogue.add('Phone')

            # Problem description
            elif dialogue == {'Greetings', 'Name', 'Phone'}:
                response = Text(text='Please describe the problem:')
                self.send(response.to_dict(), 'RESPONSE')
                dialogue.add('Problem')

            # Location
            elif dialogue == {'Greetings', 'Name', 'Phone', 'Problem'}:
                qr = quick_replies.QuickReply(title='Location',
                                              content_type='location')
                qrs = quick_replies.QuickReplies(quick_replies=[qr])
                response = Text(text='Please send the location of problem:',
                                quick_replies=qrs)
                self.send(response.to_dict(), 'RESPONSE')

        # Name
        if message['message'].get('quick_reply'):
            if message['message']['quick_reply'].get(
                    'payload') == 'open_issue' and 'Greetings' in dialogue:
                response = Text(text='Please enter your full name:')
                self.send(response.to_dict(), 'RESPONSE')
                dialogue.add('Name')

        # Live city
        if message['message'].get('quick_reply'):
            if message['message']['quick_reply'].get(
                    'payload') == 'live_city' and 'Greetings' in dialogue:
                btn = get_button(ratio='compact')
                elem = get_element(btn)
                response = GenericTemplate(elements=[elem])
                self.send(response.to_dict(), 'RESPONSE')

        # Picture
        if message['message'].get('attachments'):
            if message['message']['attachments'][0].get('type') == 'location':
                response = Text(text='Please send a picture of a problem:')
                self.send(response.to_dict(), 'RESPONSE')
                dialogue.add('Location')
            # Final state
            elif message['message']['attachments'][0].get('type') == 'image':
                response = Text(
                    text=
                    'Your ticket has been opened and we will get on it as fast as possible. If you '
                    'want to add another issue, please just greet again. Thank you!. '
                )
                self.send(response.to_dict(), 'RESPONSE')
                dialogue.add('Image')
예제 #22
0
 def test_too_many_quick_replies(self):
     qr = quick_replies.QuickReply(title='QR', payload='QR payload')
     qr_list = [qr] * 12
     with pytest.raises(ValueError) as err:
         quick_replies.QuickReplies(quick_replies=qr_list)
     assert str(err.value) == 'You cannot have more than 10 quick replies.'
예제 #23
0
 def test_quick_reply_payload_too_long(self):
     payload = 'x' * 1001
     with pytest.raises(ValueError) as err:
         quick_replies.QuickReply(title='QR', payload=payload)
     assert str(err.value) == 'Payload cannot be longer 1000 characters.'
예제 #24
0
 def test_quick_reply_invalid_type(self):
     with pytest.raises(ValueError) as err:
         quick_replies.QuickReply(title='QR', payload='test', content_type='wrong')
     assert str(err.value) == 'Invalid content_type provided.'
예제 #25
0
def process_postback(messenger, payload):
    """Function to process postbacks

    Args:
        messenger ([Messenger]): a Messenger Object
        payload ([Payload]): the payload sent by the user
    """
    init_user_preference(messenger)

    if 'START' in payload:
        send_start_messages(messenger)
        return True

    if 'MAIN_MENU' in payload:
        text = {
            "text":
            _(u'This is the main menu, select what you need bellow 👇🏼'),
            "quick_replies": get_main_menu().to_dict()
        }
        messenger.send(text, 'RESPONSE')
        return True

    if 'OPEN_SOURCE' in payload:
        qr1 = quick_replies.QuickReply(title=_('✔️ Yes'),
                                       payload='KNOW_OS_YES_FULL')
        qr2 = quick_replies.QuickReply(title=_('❌ Not yet'),
                                       payload='KNOW_OS_NO')
        qrs = quick_replies.QuickReplies(quick_replies=[qr1, qr2])
        text = {
            "text":
            _(
                u'So tell me %(first_name)s do you know what Open source'
                ' is? 👇🏼', **user),
            "quick_replies":
            qrs.to_dict()
        }
        messenger.send(text, 'RESPONSE')
        return True

    if payload.startswith('KNOW_OS_YES'):
        if 'KNOW_OS_YES_FULL' in payload:
            messenger.send({'text': _(u'Amazing!')}, 'RESPONSE')
            messenger.send_action(typing_on)
            sleep(3)

        qr1 = quick_replies.QuickReply(title=_('✔️ Yes'), payload='CVS_YES')
        qr2 = quick_replies.QuickReply(title=_('❌ Not yet'), payload='CVS_NO')
        qrs = quick_replies.QuickReplies(quick_replies=[qr1, qr2])
        text = {
            "text":
            _(u'An important component in Open Source contribution is'
              ' version control tools. Are you familiar with the concept of'
              ' version control? 👇🏼'),
            "quick_replies":
            qrs.to_dict()
        }
        messenger.send(text, 'RESPONSE')
        return True

    if 'KNOW_OS_NO' in payload:
        text = _(
            u'According to the dictionary, Open-source 🔓 software, denotes'
            ' software for which the original source code is made freely 🆓'
            ' available and may be redistributed and modified.')
        messenger.send({'text': text}, 'RESPONSE')
        messenger.send_action(typing_on)
        sleep(3)

        qr = quick_replies.QuickReply(title=_('👉🏽 Next'),
                                      payload='KNOW_OS_YES')
        qrs = quick_replies.QuickReplies(quick_replies=[qr])
        text = {
            "text":
            _(u'👩🏽‍🏫 You know ...\n✔️ Wordpress,\n✔️ Notepad++,\n✔️ Ubuntu\n'
              'and thousand of common software started out as open source'
              ' software? 👇🏼'),
            "quick_replies":
            qrs.to_dict()
        }
        messenger.send(text, 'RESPONSE')
        return True

    if 'CVS_NO' in payload:
        text = {
            "text":
            _(u'😎 Worry not!\n\n'
              'Version control allows you to manage changes to files over'
              ' time ⏱️.')
        }
        messenger.send(text, 'RESPONSE')
        messenger.send_action(typing_on)
        sleep(3)
        text = {
            "text":
            _(u'You can use version control to version code, binary files,'
              ' and digital assets 🗄️.')
        }
        messenger.send(text, 'RESPONSE')
        messenger.send_action(typing_on)
        sleep(3)
        text = {
            "text":
            _(u'This includes version control software, version control'
              ' systems, or version control tools 🧰.')
        }
        messenger.send(text, 'RESPONSE')
        messenger.send_action(typing_on)
        sleep(3)
        text = {
            "text":
            _(u'Version control is a component of software configuration'
              ' management 🖥️.')
        }
        messenger.send(text, 'RESPONSE')
        messenger.send_action(typing_on)
        sleep(3)
        qr = quick_replies.QuickReply(title=_('👉🏽 Next'), payload='CVS_YES')
        qrs = quick_replies.QuickReplies(quick_replies=[qr])
        text = {
            "text":
            _(u'😎 Now That you understand what Version control is,'
              ' let\'s explore another important topic'),
            "quick_replies":
            qrs.to_dict()
        }
        messenger.send(text, 'RESPONSE')
        return True

    if 'CVS_YES' in payload:
        qr1 = quick_replies.QuickReply(title=_('What is Git❔'),
                                       payload='GIT_1')
        qr2 = quick_replies.QuickReply(title=_('What is GitHub❔'),
                                       payload='GITHUB_1')
        qrs = quick_replies.QuickReplies(quick_replies=[qr1, qr2])
        text = {
            "text": _(u'What do you want to start with⁉️ 👇🏼'),
            "quick_replies": qrs.to_dict()
        }
        messenger.send(text, 'RESPONSE')
        return True

    if 'GITHUB_1' in payload:
        qr = quick_replies.QuickReply(title=_('👉🏽 Next'), payload='GITHUB_2')
        qrs = quick_replies.QuickReplies(quick_replies=[qr])
        text = {
            "text":
            _(u'GitHub is a code hosting platform for version control and'
              ' collaboration. It lets you and others work together on'
              ' projects from anywhere.'),
            "quick_replies":
            qrs.to_dict()
        }
        messenger.send(text, 'RESPONSE')
        return True

    if 'GITHUB_2' in payload:
        btn1 = Button(button_type='web_url',
                      title=_('Official Website'),
                      url='http://github.com')
        btn2 = Button(button_type='web_url',
                      title=_('GitHub Tutorial'),
                      url='https://guides.github.com/activities/hello-world/')
        btn3 = Button(button_type='postback',
                      title=_('🚶🏽‍♀️ Main Menu 🗄️'),
                      payload='MAIN_MENU')
        app_url = os.environ.get('APP_URL', 'localhost')
        elems = Element(
            title=_(u'Discover GitHub'),
            image_url=app_url + '/static/img/github.jpg',
            subtitle=_(
                u'Discover GitHub official website, or follow a beginner'
                ' tutorial', ),
            buttons=[btn1, btn2, btn3])
        res = GenericTemplate(elements=[elems])
        logger.debug(res.to_dict())
        messenger.send(res.to_dict(), 'RESPONSE')
        return True

    if payload.startswith('GIT_'):
        if 'GIT_1' in payload:
            messenger.send({'text': _('Good question 👌🏽')}, 'RESPONSE')
            messenger.send_action(typing_on)
            sleep(3)

        text = _(u'Git is a type of version control system (VCS) that makes'
                 ' it easier to track changes to files. ')
        messenger.send({'text': text}, 'RESPONSE')
        messenger.send_action(typing_on)
        sleep(3)

        text = _(
            u'For example, when you edit a file, Git can help you determine'
            ' exactly what changed, who changed it, and why.')
        messenger.send({'text': text}, 'RESPONSE')
        messenger.send_action(typing_on)
        sleep(3)

        qr1 = quick_replies.QuickReply(title=_('👶🏽 Install Git'),
                                       payload='INSTALL_GIT')
        qr2 = quick_replies.QuickReply(title=_('🤓 I\'ve Git Installed'),
                                       payload='CONF_GIT')
        qrs = quick_replies.QuickReplies(quick_replies=[qr1, qr2])
        text = {
            "text": _(u'Want to learn more about Git?'),
            "quick_replies": qrs.to_dict()
        }
        messenger.send(text, 'RESPONSE')
        return True

    if 'INSTALL_GIT' in payload:

        text = _(u'Time to get git installed in your machine ⭕!.')
        messenger.send({'text': text}, 'RESPONSE')
        messenger.send_action(typing_on)
        sleep(3)
        btn = Button(button_type='web_url',
                     title=_('Download Git'),
                     url='https://git-scm.com/downloads')
        elems = Element(title=_(
            u'Head over here, and donload git client based on your OS.'),
                        buttons=[btn])
        res = GenericTemplate(elements=[elems])
        logger.debug(res.to_dict())
        messenger.send(res.to_dict(), 'RESPONSE')
        messenger.send_action(typing_on)
        sleep(3)
        qr2 = quick_replies.QuickReply(title=_('Configure Git ⚒️'),
                                       payload='CONF_GIT')
        qrs = quick_replies.QuickReplies(quick_replies=[qr2])
        text = {
            "text": _(u'🧑‍🚀 Once done, let\'s configure Git'),
            "quick_replies": qrs.to_dict()
        }
        messenger.send(text, 'RESPONSE')
        return True

    if 'CONF_GIT' in payload:

        text = _(u'Great Progress so far 👨🏽‍🎓!.')
        messenger.send({'text': text}, 'RESPONSE')
        messenger.send_action(typing_on)
        sleep(2)
        text = _(u'Now let\'s configure your Git username and email using the'
                 ' following commands')
        messenger.send({'text': text}, 'RESPONSE')
        messenger.send_action(typing_on)
        sleep(2)
        text = _(u'`$ git config --global user.name "Steve Josh"`')
        messenger.send({'text': text}, 'RESPONSE')
        messenger.send_action(typing_on)
        sleep(2)
        text = _(u'`$ git config --global user.email "*****@*****.**"`')
        messenger.send({'text': text}, 'RESPONSE')
        messenger.send_action(typing_on)
        sleep(2)
        text = _(u'don\'t forget to replace Steve\'s name with your own.')
        messenger.send({'text': text}, 'RESPONSE')
        messenger.send_action(typing_on)
        sleep(2)
        text = _(u'These details will be associated with any commits that'
                 ' you create')
        messenger.send({'text': text}, 'RESPONSE')
        messenger.send_action(typing_on)
        sleep(2)
        qr = quick_replies.QuickReply(title=_('GitHub'), payload='GITHUB_1')
        qrs = quick_replies.QuickReplies(quick_replies=[qr])
        text = {
            "text": _(u'Now let\'s check what is Github👇🏼'),
            "quick_replies": qrs.to_dict()
        }
        messenger.send(text, 'RESPONSE')
        return True

    if 'FB_OS' in payload:
        text = _(u'Facebook 🧡 Open Source!')
        messenger.send({'text': text}, 'RESPONSE')
        sleep(3)

        text = _(u'Facebook manages many Open Source projects in the following'
                 ' areas:\n'
                 '✔️ Android\n'
                 '✔️ Artificial Intelligence\n'
                 '✔️ Data Infrastructure\n'
                 '✔️ Developer Operations\n'
                 '✔️ Development Tools\n'
                 '✔️ Frontend\n'
                 '✔️ iOS\n'
                 '✔️ Languages\n'
                 '✔️ Linux\n'
                 '✔️ Security\n'
                 '✔️ Virtual Reality\n'
                 '...')
        messenger.send({'text': text}, 'RESPONSE')
        sleep(3)

        btn = Button(button_type='web_url',
                     title=_('Explore them'),
                     url='https://opensource.facebook.com/projects')
        elems = Element(title=_(u'Explore Facebook Open Source projects'),
                        buttons=[btn])
        res = GenericTemplate(elements=[elems])
        logger.debug(res.to_dict())
        messenger.send(res.to_dict(), 'RESPONSE')

        return True

    if 'FORK_ON_GITHUB' in payload:
        text = _(u'🤓 You know what? This chatbot code is Open Source 🔓, it\'s'
                 ' developed by Facebook Developers Circles members around the'
                 ' world.')
        messenger.send({'text': text}, 'RESPONSE')
        sleep(5)

        text = _(
            u'%(first_name)s we welcome contributors, or simply feel free to'
            ' fork the code on GitHub, and create your own chatbot.', **user)
        messenger.send({'text': text}, 'RESPONSE')
        sleep(5)

        btn1 = Button(
            button_type='web_url',
            title=_('The Source Code'),
            url='https://github.com/fbdevelopercircles/open-source-edu-bot')
        btn2 = Button(button_type='web_url',
                      title=_('Join a circle'),
                      url='https://developers.facebook.com/developercircles')
        btn3 = Button(button_type='postback',
                      title=_('🚶🏽‍♀️ Main Menu 🗄️'),
                      payload='MAIN_MENU')
        elems = Element(title=_(u'Select an option 👇🏼'),
                        buttons=[btn1, btn2, btn3])
        res = GenericTemplate(elements=[elems])
        logger.debug(res.to_dict())
        messenger.send(res.to_dict(), 'RESPONSE')

        return True

    # the default action
    qr = quick_replies.QuickReply(title=_('🚶🏽‍♀️ Main Menu 🗄️'),
                                  payload='MAIN_MENU')
    qrs = quick_replies.QuickReplies(quick_replies=[qr])
    text = {"text": _(u'Coming soon!'), "quick_replies": qrs.to_dict()}
    messenger.send(text, 'RESPONSE')
    return False