<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mayank Kuthar</title>
    <description>The latest articles on DEV Community by Mayank Kuthar (@mayankkuthar).</description>
    <link>https://dev.to/mayankkuthar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F518757%2Fc109e3ab-10e6-4ef1-b36b-c3e887a78da9.png</url>
      <title>DEV Community: Mayank Kuthar</title>
      <link>https://dev.to/mayankkuthar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mayankkuthar"/>
    <language>en</language>
    <item>
      <title>Building a WhatsApp bot that tells a shop its daily profit</title>
      <dc:creator>Mayank Kuthar</dc:creator>
      <pubDate>Fri, 04 Dec 2026 12:23:27 +0000</pubDate>
      <link>https://dev.to/mayankkuthar/building-a-whatsapp-bot-that-tells-a-shop-its-daily-profit-794</link>
      <guid>https://dev.to/mayankkuthar/building-a-whatsapp-bot-that-tells-a-shop-its-daily-profit-794</guid>
      <description>&lt;p&gt;I built a WhatsApp bot that asks a shopkeeper three questions a day: total sales, cost of the items sold, and other expenses. It replies with the day's profit and margin, in English or Odia.&lt;/p&gt;

&lt;p&gt;It runs on Node.js, with Twilio for WhatsApp and a Vercel function as the webhook.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conversations as data
&lt;/h2&gt;

&lt;p&gt;Each conversation is a list of steps. A step has a question, the field it fills, and a check on the answer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Please enter today's total sales (₹):"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;field&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'sales'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;validator&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;/^&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;\&lt;span class="p"&gt;.&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;$&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;errorMessage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Please enter a valid amount (e.g., 5000 or 5000.50)'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One function runs every conversation, so adding Odia meant adding new steps, not new logic.&lt;/p&gt;

&lt;h2&gt;
  
  
  The bug that took the most logging
&lt;/h2&gt;

&lt;p&gt;Early on, the bot checked each answer against the previous question's rules. The fix was small: validate against the current step, then move on. Finding it took a lot of debug logs.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd change
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Storage:&lt;/strong&gt; records are kept in memory, so they disappear when Vercel shuts the function down. It needs a database.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security:&lt;/strong&gt; the webhook should check that each request really comes from Twilio.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code: &lt;a href="https://github.com/mayankkuthar/whatsapp-accounting-bot" rel="noopener noreferrer"&gt;github.com/mayankkuthar/whatsapp-accounting-bot&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>twilio</category>
      <category>serverless</category>
    </item>
  </channel>
</rss>
