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