<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Gakeredev on Medium]]></title>
        <description><![CDATA[Stories by Gakeredev on Medium]]></description>
        <link>https://medium.com/@kenedygakere?source=rss-1649cf95b32f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fVoohhM6OpM6HbWm7FXpJg.jpeg</url>
            <title>Stories by Gakeredev on Medium</title>
            <link>https://medium.com/@kenedygakere?source=rss-1649cf95b32f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 09:13:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kenedygakere/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building an Event Registration WhatsApp Chatbot]]></title>
            <link>https://medium.com/@kenedygakere/building-an-event-registration-whatsapp-chatbot-a0a99211d695?source=rss-1649cf95b32f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0a99211d695</guid>
            <category><![CDATA[chat-bot-development]]></category>
            <dc:creator><![CDATA[Gakeredev]]></dc:creator>
            <pubDate>Sat, 27 May 2023 10:36:10 GMT</pubDate>
            <atom:updated>2023-05-27T10:36:10.629Z</atom:updated>
            <content:encoded><![CDATA[<p>In today’s digital age, chatbots have become increasingly popular as a way to automate various tasks and improve customer service. One area where chatbots have found great utility is event management. In this blog post, we will explore how to build an event registration WhatsApp chatbot using Flask, Twilio, and SQLite.</p><h3>Setting Up the Environment</h3><p>To get started, we need to set up our development environment. Make sure you have Python and pip installed on your machine. Then, create a new directory for your project and navigate to it in the terminal. Here are the steps to follow:</p><ol><li>Create a new virtual environment:</li></ol><pre>$ python -m venv chatbot-env</pre><p>2.Activate the virtual environment:</p><ul><li>For Windows:</li></ul><pre>$ chatbot-env\Scripts\activate</pre><p>For macOS/Linux:</p><pre>$ source chatbot-env/bin/activate</pre><p>3.Install the required packages:</p><pre>$ pip install flask twilio</pre><h3>Building the Event Registration Chatbot</h3><p>Now that we have our environment set up, let’s start building our event registration chatbot. We will use Flask as our web framework and Twilio to integrate with the WhatsApp API. Additionally, we’ll use SQLite as our database to store user registration information.</p><p>First, create a new Python file called app.py and open it in your preferred text editor. Copy the following code into app.py:</p><pre>from flask import Flask, request<br>from twilio.twiml.messaging_response import MessagingResponse<br>import sqlite3<br>import urllib<br><br>app = Flask(__name__)<br><br>SERVICES = {<br>    &quot;1&quot;: &quot;Event registration&quot;,<br>    &quot;2&quot;: &quot;Ticket payment&quot;,<br>    &quot;3&quot;: &quot;Location information&quot;<br>}<br><br>def handle_message(body):<br>    message = body.lower()<br>    resp = MessagingResponse()<br>    responded = False<br><br>    if message == &#39;hi&#39;:<br>        resp.message(<br>            &quot;Welcome to our event services bot! Please select a service by replying with the corresponding number:\n&quot; +<br>            &quot;1. Event registration\n&quot; +<br>            &quot;2. Ticket payment\n&quot; +<br>            &quot;3. Location information\n&quot;<br>        )<br>        responded = True<br>    elif message in SERVICES.keys():<br>        service = SERVICES[message]<br>        if service == &quot;Event registration&quot;:<br>            resp.message(&quot;To register for the event, please send your name, email, and phone number separated by commas.&quot;)<br>        elif service == &quot;Ticket payment&quot;:<br>            # Add ticket prices to choose from<br>            resp.message(&quot;Please select a ticket price from the following options:\n&quot; +<br>                         &quot;1. VIP (KES 5,000)\n&quot; +<br>                         &quot;2. Regular (KES 2,000)\n&quot; +<br>                         &quot;3. Student (KES 1,000)\n&quot;)<br>        elif service == &quot;Location information&quot;:<br>            event_location = &quot;South Eastern Kenya University&quot;<br>            event_location_url = f&quot;https://goo.gl/maps/hQ72SG4vHmjgkbZT7?coh=178573&amp;entry=tt/?api=1&amp;query={urllib.parse.quote(event_location)}&quot;<br>            resp.message(f&quot;The event will be held at {event_location}. Here is the Google Maps link: {event_location_url}&quot;)<br>            responded = True<br><br>    name = None<br>    email = None<br>    phone = None<br><br>    parts = message.split(&#39;,&#39;)<br>    if len(parts) == 3:<br>        name = parts[0]<br>        email = parts[1]<br>        phone = parts[2]<br><br>        try:<br>            conn = sqlite3.connect(&#39;registration.db&#39;)<br>            c = conn.cursor()<br><br>            c.execute(&quot;INSERT INTO users (name, email, phone) VALUES (?, ?, ?)&quot;, (name, email, phone))<br>            conn.commit()<br>            conn.close()<br><br>            if c.rowcount &gt; 0:<br>                resp.message(&quot;Thank you for registering for the event!&quot;)<br>            else:<br>                resp.message(&quot;An error occurred while registering for the event. Please try again later.&quot;)<br>            responded = True<br>        except Exception as e:<br>            print(e)<br>            resp.message(&quot;An error occurred while registering for the event. Please try again later.&quot;)<br>            responded = True<br><br>    if not responded:<br>        resp.message(<br>            &quot;Sorry, I didn&#39;t understand that. Please select a service by replying with the corresponding number:\n&quot; +<br>            &quot;1. Event registration\n&quot; +<br>            &quot;2. Ticket payment\n&quot; +<br>            &quot;3. Location information\n&quot;<br>        )<br><br>    return str(resp)<br><br><br>@app.route(&#39;/bot&#39;, methods=[&#39;POST&#39;])<br>def bot():<br>    body = request.form[&#39;Body&#39;]<br>    return handle_message(body)<br><br><br>if __name__ == &#39;__main__&#39;:<br>    app.run()</pre><p>Let’s break down the code step by step:</p><ol><li>We import the necessary modules: Flask for creating the web application, request for handling HTTP requests, MessagingResponse from twilio.twiml.messaging_response to construct our Twilio responses, sqlite3 for database operations, and urllib to encode the event location URL.</li></ol><p>2. We create a Flask application instance.</p><p>3. We define a dictionary called SERVICES to map service numbers to service names.</p><p>4. The handle_message function takes a WhatsApp message body and constructs the appropriate response based on the message content. It uses the MessagingResponse object to create the response.</p><p>5.If the user sends a message saying ‘hi’, the bot responds with a welcome message and the available services.</p><p>If the user selects a service by replying with a number, the bot responds with the corresponding service details.</p><p>If the user selects the “Event registration” service, the bot prompts the user to provide their name, email, and phone number.</p><p>If the user provides the required information, the bot attempts to insert the data into the SQLite database. If successful, it sends a confirmation message; otherwise, it sends an error message.</p><p>If the user selects the “Location information” service, the bot provides the event location and a Google Maps link.</p><p>The bot function is the Flask route that receives incoming messages from Twilio. It extracts the message body and passes it to the handle_message function.</p><p>Finally, we run the Flask application if the script is executed directly.</p><h3>Database Setup</h3><p>Before running the chatbot, we need to set up the SQLite database to store user registration information. Follow these steps:</p><ol><li>Create a new directory called data in the same directory as app.py.</li></ol><p>2. Navigate to the data directory in the terminal and run the following command to create a new SQLite database file:</p><pre>$ touch registration.db</pre><p>3. Open the database file in your preferred SQLite editor (e.g., DB Browser for SQLite) and execute the following SQL statement to create a table named users:</p><pre>CREATE TABLE users (<br>    id INTEGER PRIMARY KEY AUTOINCREMENT,<br>    name TEXT,<br>    email TEXT,<br>    phone TEXT<br>);</pre><p>With the database set up, we’re ready to run our event registration WhatsApp chatbot.</p><h3>Running the Chatbot</h3><p>To run the chatbot, execute the following command in the terminal:</p><pre>$ python app.py</pre><p>Make sure the Flask application is running and accessible from the internet. You can use a tool like Ngrok to create a tunnel to your local development environment.</p><p>Once your chatbot is up and running, you can connect it to a Twilio phone number and start testing it. Configure the Twilio webhook to point to the /bot route of your Flask application.</p><h3>Conclusion</h3><p>In this blog post, we have explored how to build an event registration WhatsApp chatbot using Flask, Twilio, and SQLite. By following the steps outlined in this tutorial, you can create a functional chatbot that enables users to register for events, make ticket payments, and obtain location information. Feel free to customize and expand upon this chatbot to suit your specific requirements. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0a99211d695" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>