TUTORIAL

How to use Page Actions

A quick tutorial that builds a Smart Form with multiple paths in a single screen.

In this quick tutorial, we'll use the Page Actions feature to create multiple paths within our Smart Form, allowing for more customizable and useful workflows. Let's create a project that registers a client's upsell and presents a few options.

We'll start with the basics: importing the abstra.forms lib and creating our main Page. We're asking for a few informations, such as the account's name, plan and the account manager's email.

Adding the Page Actions is almost too easy. Where you'd usually add the run button's text, add the commands you need in a list. Here we'll open up the possibilities to create a Customer Support ticket and email the account's new manager to give them a heads up.


from abstra.forms import *

registration = Page().display("Welcome to upsell registration.") \
            .read("Enter the account here", key="account") \
            .read_dropdown("Select the account's new plan", \
            ["Startup", "Pro", "Enterprise"],
            key="plan") \
            .read_email("Enter the new account manager's email:", key = "manager_email") \
            .run(actions=["Create Customer Support ticket", "Email account manager"])

Now we're just a simple if/else statement away.


if registration.action == "Create Customer Support ticket":
    # Do something


elif registration.action == "Email account manager":
    # Do something else!

In this case, we'll add two bits of code that connect our Form to different services: Slack and Sendgrid. Slack can be reached via a request, whereas Sendgrid has it's own Python lib - all of this can be easily imported into your projects.

Check out the full code:


from abstra.forms import *
import requests
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import (Mail, Attachment, FileContent, FileName, FileType, Disposition)

slack_token = os.environ.get("SLACK_BOT_TOKEN")
sendgrid_token = os.environ.get('YOUR_SENDGRID_API_KEY')


registration = Page().display("Welcome to upsell registration.") \
            .read("Enter the account here", key="account") \
            .read_dropdown("Select the account's new plan", \
            ["Startup", "Pro", "Enterprise"],
            key="plan") \
            .read_email("Enter the new account manager's email:", key = "manager_email") \
            .run(actions=["Create Customer Support ticket", "Email account manager"])


if registration.action == "Create Customer Support ticket":
        res = requests.post(
        'https://slack.com/api/chat.postMessage',
        json={
            'channel': "sales",
            'text': "Hooray, {account} has upgraded to the {plan} plan! Book a call with the new team to smooth their transition."
        },
        headers={
            'Authorization': 'Bearer ' + slack_token,
            'Content-type': 'application/json; charset=utf-8'
        })


elif registration.action == "Email account manager":
    message = Mail(
        from_email= 'your_sender_email',
        to_emails= manager_email,
        subject='Upsell alert',
        html_content=f"""
            Hello,
            Automatic message dropping by to let you know you're now {account}'s account manager.
            They have just upgraded to the {plan} plan.
            See you later
            """)
    sg = SendGridAPIClient(sendgrid_token)
    response = sg.send(message)

Start creating task-killing forms right now.

Schedule a 15-min chat with us for a kick-start in your project here.