def process_postback()

in src/services/messenger.py [0: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 "josh@example.com"`')
        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