<?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 Andreia Almeida on Medium]]></title>
        <description><![CDATA[Stories by Andreia Almeida on Medium]]></description>
        <link>https://medium.com/@andreia_fa?source=rss-2d58abb0270d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*cda1EsX42lYzHqztm8Godw.jpeg</url>
            <title>Stories by Andreia Almeida on Medium</title>
            <link>https://medium.com/@andreia_fa?source=rss-2d58abb0270d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 13:35:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@andreia_fa/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[TrackNest — Trying to build a Smart Inventory App Without Burning Out]]></title>
            <link>https://medium.com/@andreia_fa/tracknest-trying-to-build-a-smart-inventory-app-without-burning-out-e6fb25b82fba?source=rss-2d58abb0270d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6fb25b82fba</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[project-planning-software]]></category>
            <category><![CDATA[project-management]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[project-plan]]></category>
            <dc:creator><![CDATA[Andreia Almeida]]></dc:creator>
            <pubDate>Wed, 14 May 2025 06:32:29 GMT</pubDate>
            <atom:updated>2025-05-14T06:32:29.772Z</atom:updated>
            <content:encoded><![CDATA[<h3>TrackNest — <strong>Trying to build a Smart Inventory App Without Burning Out</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*Z5Xs6JuBFAYo-5gV_8I41g.png" /></figure><p>One of the biggest issues I faced in my last side project was my complete inability to estimate how long things would take. Without even a rough timeframe or fallback strategy, everything dragged on endlessly. I didn’t feel in control, and what should have been a fun, empowering process slowly became exhausting.</p><p>So what are we doing differently this time? <br>P<strong>lanning upfront</strong>. which can definitely sound a bit ironic? How can someone accurately plan, without experience? and without major support? yeah… I had to ask Chatgpt for help, ofc 🤣</p><p><em>So here is his plan!</em><br><strong>Phase 1: Core Inventory &amp; CLI (Weeks 1–4)</strong><br>Build the foundation: project structure, database, and a CLI tool to manage inventory.</p><p><strong>Phase 2: Business Logic &amp; Alerts (Weeks 5–7)</strong><br>Add intelligent behavior: threshold checks, low-stock alerts, CLI improvements.</p><p><strong>Phase 3: Telegram &amp; Azure Integration (Weeks 8–13)</strong><br>Make it interactive and smart: Telegram reminders and image-based item detection.</p><p><strong>Phase 4: Tests, Docs, and Final Polish (Weeks 14–16)</strong><br>Test thoroughly, write full documentation, and clean up for a final release.</p><p>I’m definitely commited to the 5h/week.<br>But due to every thing that is supposed to be done…I can’t really be confident on the 16 week timeline. So his expectations is that starting on the week of 04–10.05.2026 i will end it in first week of August.<br>We a lot to learn/perfect, not asking him to do the code, etc.<br>I guess… we will see about that 😅</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6fb25b82fba" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Celebrations-bot — learning from lack of attention/failures!]]></title>
            <link>https://medium.com/@andreia_fa/celebrations-bot-learning-from-lack-of-attention-failures-33b05c4ccd57?source=rss-2d58abb0270d------2</link>
            <guid isPermaLink="false">https://medium.com/p/33b05c4ccd57</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[relational-databases]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[triggers-in-mysql]]></category>
            <dc:creator><![CDATA[Andreia Almeida]]></dc:creator>
            <pubDate>Sun, 11 May 2025 06:22:26 GMT</pubDate>
            <atom:updated>2025-05-11T06:22:26.780Z</atom:updated>
            <content:encoded><![CDATA[<h3>Celebrations-bot — learning from lack of attention/failures!</h3><p>Sure, sure, we do a lot of testing…but there’s always something failing, isn’t it? 👀 👀</p><p>In the <em>celebration bot</em>, we are supposed to store events (e.g., birthdays) in a table called <em>contact_events</em>, and the individuals receiving messages are in the <em>contacts_info</em> table. 🔍️</p><p>Some contacts are special categories like “baby” or “puppy” — and they must only be assigned the matching event type (‘baby’ or ‘puppy’, <strong>not ‘birthday’).</strong><br>To enforce this rule and detect past violations, we’ll use:</p><ul><li>A trigger (to block incorrect inserts).</li><li>A view (to audit and report past mistakes).</li></ul><p>✅ Step 1: Create a Trigger to Enforce Category Consistency</p><pre>-- Use custom delimiter to allow BEGIN/END block<br>DELIMITER //<br><br>-- Create a BEFORE INSERT trigger on the &#39;contact_events&#39; table<br>CREATE TRIGGER check_event_type_for_baby_puppy<br>BEFORE INSERT ON contact_events<br>FOR EACH ROW<br>BEGIN<br>  -- Declare a local variable to hold the category of the contact being referenced<br>  DECLARE actual_category VARCHAR(50);<br><br>  -- Look up the category in the &#39;contacts_info&#39; table using the contact_id being inserted<br>  SELECT category INTO actual_category<br>  FROM contacts_info<br>  WHERE id = NEW.contact_id;<br><br>  -- If the contact is a &#39;baby&#39; but the event type is not &#39;baby&#39;, reject the insert<br>  IF (actual_category = &#39;baby&#39; AND NEW.event_type != &#39;baby&#39;) THEN<br>    SIGNAL SQLSTATE &#39;45000&#39;<br>    SET MESSAGE_TEXT = &#39;❌ Invalid event_type: Babies must have event_type = &quot;baby&quot;&#39;;<br>  END IF;<br><br>  -- Same for puppies: if it&#39;s a puppy but the event type is not &#39;puppy&#39;, block the insert<br>  IF (actual_category = &#39;puppy&#39; AND NEW.event_type != &#39;puppy&#39;) THEN<br>    SIGNAL SQLSTATE &#39;45000&#39;<br>    SET MESSAGE_TEXT = &#39;❌ Invalid event_type: Puppies must have event_type = &quot;puppy&quot;&#39;;<br>  END IF;<br>END;<br>//<br><br>-- Restore delimiter to default<br>DELIMITER ;</pre><h3>🧠 What This Does:</h3><ul><li>Runs automatically every time someone tries to INSERT into contact_events.</li><li>Checks the referenced contact’s category (baby, puppy, person, etc.).</li><li>Rejects the insert with a meaningful error message if the event type doesn’t match the category.</li></ul><p>👁️ Step 2: Create a View to Detect Existing Mismatches</p><pre>-- This view shows any existing rows where the contact category and event_type are inconsistent<br>CREATE VIEW invalid_event_types AS<br>SELECT <br>  c.id AS contact_id,<br>  c.username,<br>  c.category,<br>  e.event_type,<br>  e.event_date<br>FROM contacts_info c<br>JOIN contact_events e ON c.id = e.contact_id<br>WHERE <br>  -- Condition 1: Contact is a baby, but event type is not &#39;baby&#39;<br>  (c.category = &#39;baby&#39; AND e.event_type != &#39;baby&#39;)<br>  OR<br>  -- Condition 2: Contact is a puppy, but event type is not &#39;puppy&#39;<br>  (c.category = &#39;puppy&#39; AND e.event_type != &#39;puppy&#39;);</pre><h3>🧠 What This Does:</h3><ul><li>Joins the contacts_info and contact_events tables.</li><li>Filters only <strong>problem rows</strong>: mismatches between category and event_type.</li><li>You can query it like any table:</li></ul><pre>SELECT * FROM invalid_event_types;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33b05c4ccd57" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Celebrations ’bot Part IV — Logic explanation]]></title>
            <link>https://medium.com/@andreia_fa/celebrations-bot-part-iv-logic-explanation-c0d78a711911?source=rss-2d58abb0270d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0d78a711911</guid>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[mysql]]></category>
            <dc:creator><![CDATA[Andreia Almeida]]></dc:creator>
            <pubDate>Sun, 04 May 2025 06:27:15 GMT</pubDate>
            <atom:updated>2025-05-04T06:27:15.066Z</atom:updated>
            <content:encoded><![CDATA[<h3>Celebrations ’bot Part IV — Logic explanation</h3><p>When I started this project, my goal wasn’t just to automate sending messages — it was to make them feel thoughtful, personal, and appropriate for every recipient.</p><p>Imagine having a personal assistant who remembers every birthday, notices when you haven’t heard from someone in a while, and sends just the right message — that’s what I wanted my bot to become.</p><p>Here’s how I built it.</p><h4>1. Contact Categories and Event Rules<br>Each contact belongs to a category:</h4><p><strong>person</strong>: normal people</p><p><strong>baby</strong>: children (special logic)</p><p><strong>puppy</strong>: dogs (special logic)</p><p>The category determines which events a contact receives:</p><p><strong>Persons</strong> can receive:</p><ul><li>Birthday messages</li><li>Christmas messages</li><li>New Year messages</li><li>Dynamic <strong>nurturing</strong> messages (explained later)</li></ul><p><strong>Babies</strong> and <strong>Puppies</strong>:</p><p>Monthly celebration messages counting their age in months. These continue every month until they reach 12 years old.</p><p><em>Why separate them?</em><br>Because a human newborn or a puppy deserves monthly milestones (“Happy 3 months!”), not the same logic used for adults.</p><p>When a new contact is created in the <em>contacts_info</em> table, their category is assigned immediately and determines their <em>celebration path</em>.</p><h4>2. Daily Event Checking<br>The bot runs once per day.</h4><p>It connects to the database and checks the <em>contact_events</em> table for events matching today’s date:</p><p><strong>Annual events:</strong> birthdays, Christmas (25 December), New Year (1 January)</p><p><strong>Monthly events: </strong>babies’ and puppies’ monthly milestones</p><p>The check uses precise SQL queries based on:</p><p><strong>recurrence</strong> = ‘annual’ for fixed-date events.</p><p><strong>recurrence</strong> = ‘monthly’ for month-count events.</p><h4>3. Message Selection and Variation<br>When preparing to send a message, the bot:</h4><p>Queries all available message templates for the given event type.</p><p>Excludes the last message that was already sent to the contact (using the message_log).</p><p>Uses random.choice() (Python’s randomizer) to select a new message from the remaining options.</p><p>If no new options exist (only one message template remains), it will resend it, but only after exhausting alternatives!</p><p>This method keeps communications feeling fresh instead of repetitive.</p><h4>4. Message Sending: Authorization, Retry, and Logging<br>Before sending a message through Telegram:</h4><p>The bot checks if the Telegram client session is authorized.</p><p>If the session is unauthorized, it automatically calls client.start(), triggering Telegram’s manual login flow (it may request a login code if needed).</p><p>Once authorized, the bot sends the message.</p><p><strong>Retry Logic:</strong></p><p>If the first attempt fails, the bot waits 5 seconds (time.sleep(5)) and tries one more time.</p><p>After two failed attempts, it logs the failure and moves on.</p><p><strong>Logging:</strong></p><p>Every message sent is recorded both in:</p><p>The <em>message_log</em> table (database) — storing <em>contact</em> ID, <em>event type</em>, <em>message</em> ID, and <em>timestamp</em>.</p><p>The server-side logs using Python’s logging module, with detailed success/failure information.</p><p>This ensures a full history exists for all messages sent, and also allows easy debugging if problems occur.</p><h4>5. Full End-to-End Flow: From Contact Creation to Message Delivery<br>Here’s the full life cycle:</h4><ol><li>Adding a New Contact!</li></ol><p>Insert into <em>contacts_info</em> with their <em>name</em>, <em>mobile number</em>, <em>category</em>, and <em>birthday</em>.</p><p>Insert their relevant events into <em>contact_events</em>:</p><p><strong>person</strong> ➔ birthday, Christmas, New Year.</p><p><strong>baby/puppy</strong> ➔ monthly events.</p><p>Don’t forget! Daily Execution → Bot starts daily.</p><p>2. Connects to MySQL database. Retrieves contacts whose events match today’s date.</p><p>3. Processing Each Contact: Fetches suitable message templates.</p><p>Avoiding repeating the <strong>last</strong> <strong>sent</strong> message (checking log table)</p><p>Personalizes message (replacing {name}, adding month counters if needed).</p><p>4. Sending the Message:</p><p>Checks Telegram session.</p><p>Sends the message (up to two tries).</p><p>Logs the sent message in the database and server logs.</p><p>Extra — Dynamic Nurturing Messages:</p><p>Separately, the bot checks if each person has received a message in the last 60 days.</p><p>If not, and if today is not their birthday, it sends a nurturing message.</p><p>As someone still learning the world of automation, I discovered that building a system like this isn’t easy — not technically, and not conceptually. Every small decision, from how to choose a message to how to manage retries, ended up shaping the final experience.</p><p>By combining structured database design, flexible message handling, and dynamic behavior, I tried to create something that feels closer to a real assistant than just a script. It’s not perfect yet, but it already creates small, meaningful moments for the people (and pets) it reaches — and for me, that was always the real goal :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0d78a711911" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Celebrations ’bot Part III — Logic explanation]]></title>
            <link>https://medium.com/@andreia_fa/celebrations-bot-part-iii-logic-explanation-95701b021b08?source=rss-2d58abb0270d------2</link>
            <guid isPermaLink="false">https://medium.com/p/95701b021b08</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Andreia Almeida]]></dc:creator>
            <pubDate>Fri, 02 May 2025 06:41:32 GMT</pubDate>
            <atom:updated>2025-05-02T06:41:32.579Z</atom:updated>
            <content:encoded><![CDATA[<h3>Celebrations ’bot Part III — Technical explanation</h3><p><strong>Bringing the Logic to Life (Full Python Implementation)</strong></p><p>Welcome back, dev friends! 🤗<br> In <a href="https://medium.com/@andreia_fa/celebrations-bot-part-i-0cd809440e03">Part I</a> and <a href="https://medium.com/@andreia_fa/celebrations-bot-part-ii-81efc897d691">Part II</a>, we built the GCP environment, installed Docker, created a MySQL container, and set up our schema.</p><p>Now it’s time for the <strong>real fun</strong>: connecting everything with <strong>Python code</strong> to bring our Celebration Bot to life. This is where it all starts running — daily, automatically, and lovingly.</p><p>Let’s go step-by-step.</p><p>Before we dive deeper, a small clarification:<br> Originally, I planned to set up the database using Docker for better efficiency and container management. However, during real-world testing, this approach proved to be less practical. 😅</p><p>The main reason was that the <strong>Google Cloud free-tier VM only provides 1 GB of memory</strong>, which is quite limited for running both Docker and MySQL reliably at the same time.<br> The VM often became unstable, leading to performance issues and service interruptions.</p><p>Because of this limitation, I chose to <strong>install MySQL directly on the VM</strong> and run the Python scripts there as well.<br> It’s not the most “elegant” or “modern” setup — but it guarantees a <strong>simpler, lighter, and more stable</strong> operation within the free-tier constraints.</p><p>At the end of the day: <strong>reliability beats fanciness</strong>, especially when working with limited resources. 🙂</p><p>🗂 Project Structure</p><p>Here’s a minimal but functional layout:</p><pre>celebration-bot/<br>├── Automate_celebration_messages.py<br>├── celebration_sql_connection.py<br>├── config.properties<br>├── main.py</pre><h3>🔧 Step 1 — Configuration</h3><p>I use a .properties file to keep sensitive info out of the code:</p><h4>config.properties — file structure</h4><pre>[Database]<br>database.url = your_url<br>database.port = your_port<br>database.username = your_usaername<br>database.password = yourpassword<br>database.db_name = your_db<br>database.messages_table = messages<br><br>[Telegram]<br>telegram.api_id = your_api_id<br>telegram.api_hash = your_api_hash<br>telegram.session_file_name = session_name</pre><h3>💾 Step 2 — Database Logic</h3><p>All database operations are handled in celebration_sql_connection.py.<br> This module is carefully designed to make the system <strong>safe and reliable</strong>:</p><ul><li>It <strong>checks</strong> if a contact already received a message today and <strong>skips</strong> them automatically.</li><li>It <strong>avoids sending duplicate messages</strong> by excluding the last message sent.</li><li>It <strong>defaults safely</strong> (e.g., if a contact’s category is missing, it falls back to “birthday” messages).</li><li>It includes <strong>special logic</strong> for &quot;puppy&quot; and &quot;baby&quot; event types, calculating the <strong>number of months</strong> since their birth date.</li></ul><p>All possible errors (database issues, connection problems, missing data) are <strong>handled gracefully</strong>, ensuring the bot keeps running without crashing.</p><h3>Sample usage:</h3><pre>mysql_cnx = CelebrationSqlConnection.connect_to_mysql(host, port, user, password, db)<br>contacts = sql_connection.get_contacts_for_today_events(mysql_cnx)</pre><h3>💬 Step 3 — Telegram Messaging Logic</h3><p>Everything related to the messaging flow is handled in Automate_celebration_messages.py:</p><ul><li>Verifies whether a contact is due for a celebration or nurturing message;</li><li>Fetches a new (non-duplicate) message from the DB;</li><li>Sends it using <strong>Telethon;</strong></li><li>Implements <strong>retry logic;</strong></li><li>Logs the message back to the DB;</li></ul><p>I tried my best to think about all possible worst-cases and prevent them from happening, in the code:</p><ul><li>Re-authentication fallback;</li><li>Retry on failure (2 tries);</li><li>Session handling;</li><li>Different strategies per message type;</li></ul><h3>🧠 Step 4 — The Main Execution Flow</h3><p>In main.py, we stitch everything together:</p><pre>from Automate_celebration_messages import Automate_messages<br>from celebration_sql_connection import CelebrationSqlConnection</pre><ul><li>Load config values;</li><li>Establish DB connection;</li><li>Initialize the bot;</li><li>Check for celebration messages and send them;</li><li>Check for nurturing messages and send them;</li><li>Log results;</li><li>Shut down safely;</li></ul><h3>🕰 Step 5 — Automate with Cron</h3><p>Because I wanted to be able to run it automatically</p><p>First, install cron if it’s not already installed:</p><pre>sudo apt-get update<br>sudo apt-get install cron</pre><p>Make sure the cron service is running:</p><pre>sudo service cron start</pre><p>And now, just open it an adapt teh follwoing path according to your project:</p><pre>crontab -e</pre><p>And add the following line (adjust the paths for your project):</p><pre>0 9 * * * cd /your/project/path &amp;&amp; /usr/bin/python3 main.py &gt;&gt; /your/project/path/cron.log 2&gt;&amp;1</pre><p><strong>Explanation</strong>:</p><ul><li>0 9 * * * → Runs the job every day at <strong>09:00 AM</strong>.</li><li>cd /your/project/path → Navigate to your Celebration Bot project folder.</li><li>/usr/bin/python3 main.py → Execute your Python script.</li><li>&gt;&gt; /your/project/path/cron.log 2&gt;&amp;1 → Save all output (standard and error) into a cron.log file for easy debugging.</li></ul><p>✅ <strong>Testing Tip:</strong><br> If you want to test it immediately, you can temporarily set it to run every minute!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95701b021b08" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Celebrations ’bot — Part II]]></title>
            <link>https://medium.com/@andreia_fa/celebrations-bot-part-ii-81efc897d691?source=rss-2d58abb0270d------2</link>
            <guid isPermaLink="false">https://medium.com/p/81efc897d691</guid>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[mysql]]></category>
            <dc:creator><![CDATA[Andreia Almeida]]></dc:creator>
            <pubDate>Tue, 29 Apr 2025 06:32:43 GMT</pubDate>
            <atom:updated>2025-04-29T11:01:28.588Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome back, friends! 💛<br>Buckle up and hold tight!</p><p>This is where the hard work starts ⚒️</p><p>Ideally, we will need a docker to run our database (if you have resources feel free to use Cloud SQL — but<strong> it does not belong to the free</strong> tier from GCP).</p><p>Let’s start with that, then! Go to your Compute engine, next to the SSH button you will find <em>an arrow</em>, press on it and select the option <em>open in a new browser window</em>.</p><p>You will now be facing a Debian GNU/Linux terminal with your_google_account@name_of_yourproject. let’s start by creating and installing the docker, shall we?</p><p>By default, GCP is using <strong>Debian Bookworm</strong>, so we should use Debian (and not Ubuntu) commands to install Docker:</p><pre># Update the apt package index and install packages to allow apt to use a repository over HTTPS<br>sudo apt-get update<br>sudo apt-get install -y ca-certificates curl gnupg<br><br># Add Docker&#39;s official GPG key<br>sudo install -m 0755 -d /etc/apt/keyrings<br>curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg<br>sudo chmod a+r /etc/apt/keyrings/docker.gpg<br><br># Set up the repository<br>echo \<br>  &quot;deb [arch=&quot;$(dpkg --print-architecture)&quot; signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \<br>  &quot;$(. /etc/os-release &amp;&amp; echo &quot;$VERSION_CODENAME&quot;)&quot; stable&quot; | \<br>  sudo tee /etc/apt/sources.list.d/docker.list &gt; /dev/null<br><br># Update the apt package index<br>sudo apt-get update<br><br># Install Docker<br>sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin</pre><p>After it, try our friendly “Hello World” to check if everything is working as expected:</p><pre>sudo docker run hello-world</pre><p>👉 We should have in mind that, <strong>as a best practice</strong>, we should not use <em>sudo </em>commands (only when <em>extremely </em>necessary<em>)</em>! Hence, we should add our user to the docker group, which grants permissions to run Docker commands directly, here’s how:</p><pre>-- Check if you have a group:<br>getent group docker<br><br>-- If not, create it:<br><br>sudo groupadd docker<br><br>--  check your username:<br>whoami<br><br>-- Add your username to the docker group:<br>sudo usermod -aG docker YOURusername<br><br>-- Log out/in or simply refresh it to verify it:<br>newgrp docker<br><br>-- now you should be able to simply run (without sudo:):<br>docker ps</pre><p>Now, let’s create a container, to run a MySql docker image! 📃</p><pre>-- if you don&#39;t have it already, download the image of Mysql:<br>docker pull mysql:latest<br><br>-- start a new mysql container (modifying the fields above - name, password and db_name:<br>docker run --name YOUR-container -e MYSQL_ROOT_PASSWORD=YOUR-rootpassword -e MYSQL_DATABASE=YOUR_db -p 3306:3306 -d mysql:latest<br><br>-- access the Mysql shell within the Container:<br>docker exec -it YOUR-container /bin/bash<br><br>-- Connect to mysql (it will prompt your password):<br>mysql -u root -p<br><br>-- If you need to reboot your machine, just start the container again with:<br>docker start Name_container</pre><p>Here’s my DB schema:</p><pre>CREATE TABLE contacts_info (<br>    id SERIAL PRIMARY KEY,<br>    username VARCHAR(255) NOT NULL,<br>    personal_relationship VARCHAR(255),<br>    message_receiver VARCHAR(255) NOT NULL,<br>    telegram_id VARCHAR(255),<br>    birthday_date DATE,<br>    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,<br>    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP<br>);<br><br>CREATE TABLE contact_events (<br>    id SERIAL PRIMARY KEY,<br>    contact_id INT REFERENCES contacts_info(id) ON DELETE CASCADE,<br>    event_type VARCHAR(50) NOT NULL,<br>    recurrence VARCHAR(50) NOT NULL,<br>    event_date DATE,<br>    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP<br>);<br><br>CREATE TABLE messages (<br>    id SERIAL PRIMARY KEY,<br>    text_message TEXT NOT NULL,<br>    type VARCHAR(50) NOT NULL,<br>    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP<br>);<br><br>CREATE TABLE message_log (<br>    id SERIAL PRIMARY KEY,<br>    contact_id INT REFERENCES contacts_info(id) ON DELETE CASCADE,<br>    message_id INT REFERENCES messages(id) ON DELETE SET NULL,<br>    sent_message TEXT NOT NULL,<br>    date_sent TIMESTAMP DEFAULT CURRENT_TIMESTAMP,<br>    status VARCHAR(50) CHECK (status IN (&#39;sent&#39;, &#39;failed&#39;, &#39;pending&#39;)) DEFAULT &#39;pending&#39;<br>);</pre><ul><li><strong>contacts_info</strong> stores your contacts and personal information.</li><li><strong>contact_events</strong> defines the types of celebrations (birthday, Christmas, etc.).</li><li><strong>messages </strong>stores templates of the messages you want to send.</li><li><strong>message_log</strong> keeps track of when and what messages were sent.</li></ul><p>Here is some examples, real data will vary according to your contacts and events:</p><pre>-- Example: Insert into contacts_info<br>INSERT INTO contacts_info (username, personal_relationship, message_receiver, telegram_id, birthday_date)<br>VALUES (&#39;John Doe&#39;, &#39;Friend&#39;, &#39;John&#39;, &#39;123456789&#39;, &#39;1990-01-01&#39;);<br><br>-- Example: Insert into contact_events<br>INSERT INTO contact_events (contact_id, event_type, recurrence, event_date)<br>VALUES (1, &#39;Birthday&#39;, &#39;Yearly&#39;, &#39;1990-01-01&#39;);<br><br>-- Example: Insert into messages<br>INSERT INTO messages (text_message, type)<br>VALUES (&#39;Happy Birthday, dear friend!&#39;, &#39;Birthday&#39;);<br><br>-- Example: Insert into message_log<br>INSERT INTO message_log (contact_id, message_id, sent_message, status)<br>VALUES (1, 1, &#39;Happy Birthday, dear friend!&#39;, &#39;sent&#39;);</pre><p>As good practice, please remember to Stop your Docker (and the entire machine), after a session of work. It’s usually recommended as a good security, cost efficiency and Data integrity measure :)</p><pre>docker stop &lt;YOUR_container&gt;<br><br>-- to stop all containers<br><br>docker stop $(docker ps -q)</pre><p>To start it all over again, open the ssh-terminal:</p><pre>-- to start docker<br><br>docker ps<br><br>-- to start your container<br><br>docker exec -it YOUR_container /bin/bash<br><br>-- to start mysql<br><br>mysql -u root -p<br><br>-- to acess your db:<br><br>USE YOUR_db;</pre><p>Now that, the db is finished let’s move to the final stage, code and logic!<br>keep tuned with part III! 🤗</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81efc897d691" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Celebration’s Bot — Part I]]></title>
            <link>https://medium.com/@andreia_fa/celebrations-bot-part-i-0cd809440e03?source=rss-2d58abb0270d------2</link>
            <guid isPermaLink="false">https://medium.com/p/0cd809440e03</guid>
            <category><![CDATA[bots]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Andreia Almeida]]></dc:creator>
            <pubDate>Sat, 26 Oct 2024 13:31:50 GMT</pubDate>
            <atom:updated>2025-04-29T11:00:41.744Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever felt the desire to automate SMS’s?<br>Some years ago, I had the thought <em>“what if I could automate some SMSs, so I don’t even have to think about them?”,</em> just to save some headspace.<br>The reality is, I did some research on the SMS protocol that the idea eventually died. 😂</p><p>Years later, with the boom of the Telegram bots and their Telethon app, it was impossible not to fulfill the desire!</p><p>So, welcome to what I call: “Celebration Bot” it is meant to send your favorite contacts, all the celebration wishes all around: <em>Birthday</em>, <em>Christmas </em>and <em>New Year’s</em>. And because, everyone likes a bit of love, you can also send <em>nurturing </em>messages, with the end goal of doing a bi-monthly check-in, sending them some love as a conversation starter and creating a beautiful and sweet routine to check on your favorite people regularly.</p><p><em>As a disclaimer</em>, I must say, automation by itself will not guarantee long lasting relationships. But it will help with building the routine, the rest of the communication skills, have to come from the user, himself 🙈.</p><p>Technical requirements:</p><ul><li>Telegram;</li><li>GCP (Google Cloud Platform)/Local computer with scheduler (I’m using CGP so the code is adapted to it).</li></ul><p>Configuring GCP 90-day free account (forever!):</p><p>Using <em>your Gmail account</em> or similar, access GCP and start your free 90-day trial. Follow the steps below to be sure that <em>you will not have any surprises after the 90 days.</em></p><ol><li>Create your project:</li></ol><p>When you sign in, GCP promptly starts your new project with the name: ”My first Project”. You can easily change it (or not!) on your project settings.</p><blockquote>I would suggest creating a budget alert, under the category <em>Billing</em>. <br>Select Budgets<em> and Alerts</em> and set it to 0$. This with the <em>strict </em>use of <em>only free resources </em>in the Free-tier level, will give you peace of mind.</blockquote><p><strong>Be aware of your limits!</strong><br>Some examples of free resources that are available for free within usage limits. Examples include:</p><ul><li><strong>Compute Engine</strong>: e2-micro instance per month in select regions (US).</li><li><strong>Google Cloud Functions</strong>: 2 million invocations per month.</li><li><strong>Cloud Storage</strong>: 5 GB of regional storage per month.</li><li><strong>Cloud Pub/Sub</strong>: 10 GB of messages per month.</li><li><strong>BigQuery</strong>: 1 TB of queries per month.</li></ul><p>For this specific project, you don’t really need anything more than a Computer Engine. Let me show you, how 🤗</p><p>2. Setting up your <em>free compute Engine</em></p><p>In the left-hand navigation menu, go to <strong>Compute Engine</strong> &gt; <strong>VM instances</strong>.</p><p>If it’s your first time using Compute Engine, you’ll need to click <strong>Enable</strong> to activate the API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*IN7cixj4L8XOOmqEhQuw_A.png" /></figure><p>Once the Compute Engine API is enabled, click <strong>Create Instance</strong> at the top of the page, customize it with a suitable name, but most important make sure you hit the free properties:</p><ul><li>Machine Type: <strong>e2-micro</strong> (GCP offers some free regions in America just check online for a list and easily pick the one closest to your location).</li><li>Disk Size: <strong>Standard persistent disk </strong>10 GB (I believe this is the default one for e-2 micro).</li><li>VM Provisioning model: <strong>Standart</strong></li><li>External IP: Ephemeral (it’s the default one :).</li></ul><p>You should end up with something like:</p><p><strong>Region:</strong> Us-central1 (Iowa);<br><strong>Machine configuration: </strong>E2 (low-cost day-to-day computing);<br><strong>Machine type: </strong>e2-micro (2vCPU, 1 core, 1GB memory);<br><strong>Boot disk: </strong>make sure to <strong>change </strong>from <em>Balanced </em>(default)<em> </em>to<strong> </strong><em>Standard </em>persistent disk.<br><strong>Firewall: </strong>do not select http/https.</p><p>If you made it, this far, you are now ready to go! <br>Check part II to start the configuration part! See you there! 🤗</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0cd809440e03" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>