Home / DialogFlow ES / How to save user input to an Airtable database in Dialogflow ES
DialogFlow ES

How to save user input to an Airtable database in Dialogflow ES

In this tutorial, I will explain how you can save the data you collected from the lead capture bot and save it to Airtable.

Why Airtable?

Airtable is the best low code database for non-programmers who are building Dialogflow chatbots

In the user.provides.url intent, enable the “Enable webhook call for this intent” toggle switch at the bottom of the intent.

This is the Python code you will use in the webhook. If you are not clear on how to get started with Python for Dialogflow, check out the resources below.

Resources

Python webhook tutorial
How to set up Python webhook debugging using ngrok

This is the webhook route in the Flask app

@app.route('/webhook', methods=['POST'])
def hello_webhook():
    req = request.get_json(silent=True, force=True)
    result = save_to_db(req)
    return {
        'fulfillmentText': str(result)
    }

This is the code for the save_to_db method

def save_to_db(req):
    try:
        query_result = req.get('queryResult')
        output_contexts = query_result.get('outputContexts')
        session_vars = next(
            context for context in output_contexts if str(context.get('name')).endswith('/session-vars'))

        name = session_vars.get('parameters').get('person').get('name')
        email = session_vars.get('parameters').get('email')
        url = query_result.get('parameters').get('url')

        table = Table(api_key, base_id, table_name)
        result = table.create({'Name': name, 'Email': email, 'Website': url})
        return 'Thanks. We will be in touch soon.'
    except Exception as e:
        error_str = str(e)
        return 'Something went wrong. Please try again later'

Remember to add the ngrok generate URL to your fulfillment

Demo

This is what the output looks like in Dialogflow Messenger

And you can see that the data we input has been saved to Airtable

<— End of article —>


This website contains affiliate links. See the disclosure page for more details. 
"The magic key I needed as a non-programmer"

The custom payload generator was the magic key I needed (as a non-programmer) to build a good demo with rich responses in DialogFlow Messenger. I've only used it for 30 minutes and am thrilled. I've spent hours trying to figure out some of the intricacies of DialogFlow on my own. Over and over, I kept coming back to Aravind's tutorials available on-line. I trust the other functionalities I learn to use in the app will save me additional time and heartburn.

- Kathleen R
Cofounder, gathrHealth
"Much clearer than the official documentation to be honest"

Thanks a lot for the advice (of buying and following your videos)! They helped a lot indeed. Everything is very clear when you explain, much clearer than the official documentation to be honest 🙂

Neuraz T
Review for Learn Dialogflow CX
"I will strongly recommend this course because even I can learn how to design chatbot (no programming background)"

I think Aravind really did a great job to introduce dialogflow to people like me, without programming background. He organizes his course in very clear manner since I have been a college professor for 20 years. It is very easy for me to recognize how great Aravind’s course is! Very use-friend and very easy to follow. He doesn’t have any strong accent when he gives the lectures. It is so easy for me to understand. Really appreciate it.

Yes, I will strongly recommend this course because even I can learn how to design chatbot (no programming background) after studying Avarind’s course, you definitely can!

Ann Cai
Review for Learn Dialogflow ES

Similar Posts