<?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 Danny Vien on Medium]]></title>
        <description><![CDATA[Stories by Danny Vien on Medium]]></description>
        <link>https://medium.com/@defuera?source=rss-24b03a8caa48------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2Q03ri0FPxWGY1W6RIVRjw.png</url>
            <title>Stories by Danny Vien on Medium</title>
            <link>https://medium.com/@defuera?source=rss-24b03a8caa48------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 20:25:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@defuera/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[Chatterbox: A Comprehensive Framework for Building Dialogs with Telegram Chatbots]]></title>
            <link>https://medium.com/dev-artel/chatterbox-a-comprehensive-framework-for-building-dialogs-with-telegram-chatbots-fde2cabd93f0?source=rss-24b03a8caa48------2</link>
            <guid isPermaLink="false">https://medium.com/p/fde2cabd93f0</guid>
            <category><![CDATA[chatbot-development]]></category>
            <category><![CDATA[telegram-bot]]></category>
            <category><![CDATA[dart]]></category>
            <dc:creator><![CDATA[Danny Vien]]></dc:creator>
            <pubDate>Thu, 18 Jan 2024 13:57:48 GMT</pubDate>
            <atom:updated>2024-01-18T14:22:02.739Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t8y4oMXekqjTMx5IldIWMg.png" /></figure><h3>Intro</h3><p>Chatbots are becoming increasingly popular because users can interact with them within the app they are already using. That’s why building a user-facing product as a chatbot is a good idea for product validation.</p><p>Developing a chatbot requires less time to test your idea since there is no need to create a UI. Instead, you can focus on implementing a dialog flow.</p><p>We created Chatterbox to simplify complex dialog flows and maintain context.</p><h3>Problem</h3><p>The most straightforward method of communicating with the Telegram Bot API is by utilizing their REST API. However, this can be challenging for the average developer and may impede the development process. To accelerate development, API wrappers such as <a href="https://pub.dev/packages/televerse">Televerse</a> or Teledart can be used. These wrappers do not, however, offer high-level abstractions for intricate dialog flows.</p><h3>Solution</h3><p>Check <a href="https://medium.com/@oktaykopcak/testing-your-telegram-bot-with-ngrok-a-step-by-step-guide-81c8c4a9a853">this article</a> on how to set up a Telegram bot and connect it to a local machine with <a href="https://ngrok.com/download">ngrok</a>.</p><p>Let’s start with concept and components of Chatterbox. The base building block of a Chatterbox app is a <strong>Flow</strong>. A <strong>Flow</strong> is a conversation branch that can be triggered by one of the following events:</p><ul><li>Command (starts with ‘/’)</li><li>Arbitrary user input</li><li>Redirect from another <strong>Flow</strong></li></ul><p>A <strong>Flow</strong> consists of <strong>Step</strong>s. For example, in an onboarding <strong>Flow</strong>, a chatbot may gather a user&#39;s email, name, and age. This <strong>Flow</strong> consists of three <strong>Step</strong>s, which can be triggered by user input or by another <strong>Step</strong>, and produce a chatbot <strong>Reaction</strong>.</p><p><strong>Reaction</strong> types:</p><ul><li><strong>None</strong> – no reaction</li><li><strong>Response</strong> – send a message to a user</li><li><strong>Redirect</strong> – invoke another <strong>Step</strong> or <strong>Flow</strong></li><li><strong>Invoice</strong> – issue an invoice for a user</li><li><strong>Composed</strong> – combines several reactions</li></ul><p><strong>Steps</strong> are identified and can be linked by <strong>URIs. URI </strong>is inferred from <strong>Step </strong>name (<em>for that reason every step in your program must use unique name</em>) and might include arguments. <a href="https://core.telegram.org/bots/api#inlinekeyboardbutton">Telegram enforces limit of 64 bytes</a> for such data. To produce a <strong>URI</strong> use extension method toStepUri:</p><pre>(MyStep).toStepUri([&quot;param1&quot;, &quot;param2&quot;])</pre><p>Notice, that all arguments are strings. They can be received in MyStep handle method:</p><pre>Future&lt;Reaction&gt; handle(MessageContext messageContext, [List&lt;String&gt;? args])</pre><h3>Example</h3><h3>Game concept</h3><p>To illustrate key concepts, let’s develop a simple yet fun and enjoyable game. The game rules are very simple:</p><blockquote><em>In the game of 21 Sticks, two players take turns removing 1 to 3 sticks from a total of 21. The player who takes the last stick loses.</em></blockquote><p>The game can be implemented as a single Chatterbox <strong>Flow:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FCdJHUNwupEMJuPOB7a22g.png" /><figcaption>Game Flow Diagram</figcaption></figure><h3>Detailed description</h3><p>Chatterbox is initialized by following params:</p><ul><li>botToken— see <a href="https://core.telegram.org/bots/api#authorizing-your-bot">Telegram documentation</a> to get one</li><li>flows— an array of flows, we’ll create one below</li><li>store — a way to keep conversation context between invocations. For this example we’ll use InMemoryStore(), kindly provided by the library</li></ul><pre>final flows = &lt;Flow&gt;[ CountdownGameFlow()];<br>Chatterbox(botToken: botToken, flows: flows, store: InMemoryStore()).invokeFromWebhook(json);</pre><p><strong>Flow</strong> is simply an array of steps</p><pre>class TwentyOneSticksGameFlow extends Flow {<br>  @override<br>  List&lt;StepFactory&gt; get steps =&gt; [<br>    //todo<br>  ];<br>}</pre><p>Now we’ll be adding those steps one by one:</p><ul><li>The flow begins with <strong>StartStep</strong>, which greets the user and redirects to a <strong>User</strong> step. To greet the user and begin waiting for their turn, we combine two reactions using <strong>ReactionComposed</strong>. <strong>ReactionRedirect</strong> then redirects the execution flow to a provided <strong>Step</strong>.</li></ul><pre>class StartStep extends FlowStep {<br>  @override<br>  Future&lt;Reaction&gt; handle(MessageContext messageContext, [List&lt;String&gt;? args]) async {<br>    return ReactionComposed(responses: [<br>      ReactionResponse(<br>        text:<br>            &quot;In the game of 21 Sticks, two players take turns removing 1 to 3 sticks from a total of 21. The player forced to take the last stick loses.&quot;,<br>      ),<br>      ReactionRedirect(stepUri: (_UserTurnStep).toStepUri())<br>    ]);<br>  }<br>}</pre><ul><li>The next <strong>Step</strong> is to wait for user keyboard input. An inline keyboard displays buttons under the message text. The <strong>InlineButton</strong> receives a <strong>nextStepUri</strong> parameter that defines the <strong>Step</strong> to be invoked on a button click. Also, note the array of parameters that are passed to the next <strong>Step</strong> via a URI.</li></ul><pre>class _UserTurnStep extends FlowStep {<br>  @override<br>  Future&lt;Reaction&gt; handle(MessageContext messageContext, [List&lt;String&gt;? args]) async {<br>    final number = (args?.firstOrNull ?? &#39;21&#39;);<br><br>    return ReactionResponse(<br>        text: &#39;There are $number sticks.\\n\\nHow many sticks do you want to take?&#39;,<br>        buttons: [<br>          InlineButton(title: &#39;One&#39;, nextStepUri: (_GameProcessingStep).toStepUri([_Player.user.name, number, &#39;1&#39;])),<br>          InlineButton(title: &#39;Two&#39;, nextStepUri: (_GameProcessingStep).toStepUri([_Player.user.name, number, &#39;2&#39;])),<br>          InlineButton(title: &#39;Three&#39;, nextStepUri: (_GameProcessingStep).toStepUri([_Player.user.name, number, &#39;3&#39;])),<br>        ].sublist(0, min(3, int.parse(number))));<br>  }<br>}</pre><ul><li>Once a user submits input, the <strong>_GameProcessingStep</strong> is triggered. First, we retrieve the passed parameters and determine if the game has finished or can be continued. It is important to note that we use <strong>ReactionComposed</strong> again, but this time to edit a previous message with buttons that display the user&#39;s choice in the same message, rather than submitting to new messages. We then pass control flow to the next step. If a winner is determined, the <strong>_OnPlayerWonStep</strong> is invoked by passing the winner as a parameter. Otherwise, the game continues.</li></ul><pre>class _GameProcessingStep extends FlowStep {<br>  @override<br>  Future&lt;Reaction&gt; handle(MessageContext messageContext, [List&lt;String&gt;? args]) async {<br>    final actor = _Player.values.byName(args!.first);<br>    final originalNumber = int.parse(args.elementAtOrNull(1)!);<br>    final playerChoice = int.parse(args.elementAtOrNull(2)!);<br><br>    final sticksLeft = originalNumber - playerChoice;<br><br>    final reaction = switch (sticksLeft) {<br>      1 =&gt; ReactionRedirect(stepUri: (_OnPlayerWonStep).toStepUri([actor.name])),<br>      0 =&gt; ReactionRedirect(stepUri: (_OnPlayerWonStep).toStepUri([actor.getOpponent.name])),<br>      _ =&gt; ReactionRedirect(stepUri: (_GameLooperStep).toStepUri([actor.name, &#39;$sticksLeft&#39;])),<br>    };<br><br>    return ReactionComposed(responses: [<br>      if (actor == _Player.user)<br>        ReactionResponse(<br>          text: &#39;There are $originalNumber sticks.\\n\\nYou took out $playerChoice sticks.&#39;,<br>          editMessageId: messageContext.editMessageId,<br>        ),<br>      reaction,<br>    ]);<br>  }<br>}</pre><ul><li>The purpose of <strong>GameLooperStep</strong> is to determine whose turn it is:</li></ul><pre>class _GameLooperStep extends FlowStep {<br>  @override<br>  Future&lt;Reaction&gt; handle(MessageContext messageContext, [List&lt;String&gt;? args]) async {<br>    final actor = _Player.values.byName(args!.first);<br>    final sticksLeft = int.parse(args.elementAtOrNull(1)!);<br><br>    return switch (actor) {<br>      _Player.user =&gt; ReactionRedirect(stepUri: (_BotTurnStep).toStepUri([&#39;$sticksLeft&#39;])),<br>      _Player.bot =&gt; ReactionRedirect(stepUri: (_UserTurnStep).toStepUri([&#39;$sticksLeft&#39;])),<br>    };<br>  }<br>}</pre><ul><li><strong>BotTurnStep</strong> implements the logic for the bot to draw a random number of sticks. To prevent the bot from drawing more sticks than are available, the <strong>min()</strong> function is used.</li></ul><pre>class _BotTurnStep extends FlowStep {<br>  @override<br>  Future&lt;Reaction&gt; handle(MessageContext messageContext, [List&lt;String&gt;? args]) async {<br>    final sticksLeft = int.parse(args!.first);<br><br>    final botTurn = Random().nextInt(min(3, sticksLeft)) + 1;<br><br>    await Future.delayed(Duration(milliseconds: 300));<br><br>    return ReactionComposed(responses: [<br>      ReactionResponse(<br>        text: &#39;There are $sticksLeft sticks.\\n\\nBot takes out $botTurn sticks.&#39;,<br>      ),<br>      ReactionRedirect(<br>        stepUri: (_GameProcessingStep).toStepUri([&#39;bot&#39;, sticksLeft.toString(), botTurn.toString()]),<br>      ),<br>    ]);<br>  }<br>}</pre><ul><li>Finally, the last <strong>Step</strong> is to congratulate the winner or mock the loser.</li></ul><pre>class _OnPlayerWonStep extends FlowStep {<br>  @override<br>  Future&lt;Reaction&gt; handle(MessageContext messageContext, [List&lt;String&gt;? args]) async {<br>    final actor = _Player.values.byName(args!.first);<br><br>    final text = switch (actor) {<br>      _Player.user =&gt; &#39;Congratulations, you won! 🎉✨&#39;,<br>      _Player.bot =&gt; &#39;Oh, no, you are a looser! 💩😱&#39;,<br>    };<br><br>    return ReactionComposed(responses: [<br>      ReactionResponse(<br>        text: text,<br>      ),<br>    ]);<br>  }<br>}</pre><h3>Outro</h3><p>Investigate the libraries <a href="https://github.com/DevArtel/chatterbox">code</a> or run the example yourself.</p><p>Or jump directly to Telegram to play amazing game of sticks with <a href="https://t.me/AmazingGameOfSticksBot">AmazingGameOfSticksBot</a>!</p><p>Thanks for your attention. <a href="/service/mailto:info@devartel.io">Let us know</a> if you need the library in some other language.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fde2cabd93f0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dev-artel/chatterbox-a-comprehensive-framework-for-building-dialogs-with-telegram-chatbots-fde2cabd93f0">Chatterbox: A Comprehensive Framework for Building Dialogs with Telegram Chatbots</a> was originally published in <a href="https://medium.com/dev-artel">Dev Artel</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[On the importance of crypto]]></title>
            <link>https://medium.com/@defuera/on-the-importance-of-crypto-1f51bda44a67?source=rss-24b03a8caa48------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f51bda44a67</guid>
            <dc:creator><![CDATA[Danny Vien]]></dc:creator>
            <pubDate>Tue, 10 Aug 2021 10:56:51 GMT</pubDate>
            <atom:updated>2025-05-11T08:00:57.647Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*gK-T15ln0OMWBNMD5Jzx9A.gif" /></figure><p><em>In this post term </em><strong><em>crypto</em></strong><em> is used to describe a digital asset, that cannot be copied, but only passed from one owner to another. It can be a digital photo, mp3 file or cryptocurrency asset.</em></p><h3>The digital realm</h3><p>Modern world is moving into a digital space with ever accelerating velocity.</p><p>This is an exciting and fascinating change. It allows us to travel around the world almost for free without lifting our butt from the chair. Enables us to communicate with our friends and family who leave thousands kilometers away with crystal clear picture on a daily basis, it saves us time shopping online and buying tons of shit.</p><p>Skeptics say: “It doesn’t feel the same”, “It can’t replace meeting in person or actually travelling to Tanzania”. Of course it can’t. Yet. But this is not the point, what important is the trend. Try to remember how much of your life was in digital space 5 years ago. Then think for a moment what’s happening today and then interpolate it 5 years forward, go wild! And still you will be off, way off. Our brain is not so good in projecting exponential trends, but the technology does evolve exponentially. Which means you cannot imagine what the world will look like in 5 years. In 10 years? — don’t even try.</p><h3>True digital ownership</h3><p>How important is crypto in this context? It is very important, it is a distance between North Korea and Switzerland. It is a prefix between utopia and anti-utopia. And almost no one gets it, except crypto geeks, cyberpunks and some online activists. It’s terrifying, but there’s a hope. Global warming movement, <a href="https://en.wikipedia.org/wiki/Electronics_right_to_repair">right to repair</a>, privacy scandals, <a href="https://en.wikipedia.org/wiki/Deplatforming">deplatforming</a> and data ownership concerns. More and more people are realising that they are being manipulated by social media algorithms pressing the dopamine button. People seem to be waking up.</p><p>We are in a race to wake up before it’s too late.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p_gmWAvv6n17GQ1o10PlOg.png" /></figure><p>What am I talking about? Way before ownership was based solely on force. Difference between having a movable or immovable object was whether you can keep everyone else forcefully take it from you. Later we built states and for the majority of cases ownership started to be guaranteed by the authority. In the modern digital space ownership is guaranteed by the corporations. It’s not even guaranteed, but rather temporary granted. Did you read Terms of Service? It’s not even the ownership, it’s lending. Temporary usage in exchange for your data, clicking an ad or a monthly subscription.</p><p>You don’t own “your” YouTube account, it can be closed any minute and your blogger career can be thrown away (<a href="https://www.youtube.com/watch?v=P5NN9HicCUs">YouTube bans hundreds of content makers</a>, <a href="https://reason.com/2019/03/11/learn-to-code-twitter-harassment-ross/">Twitter bans</a>, <a href="https://www.buzzfeednews.com/article/laurenstrapagiel/twitch-karupups-suspended-blackface-cosplay-apex">Twitch bans</a>). You don’t own any letter that you post on medium and you don’t own any item you win in the video game of your preference. You just granted an access until the real owner decides to restrict you for whatever reason.</p><p>Don’t forget about the governments (<a href="https://en.wikipedia.org/wiki/Blocking_Telegram_in_Russia#:~:text=On%20April%2013%2C%20Moscow&#39;s%20Tagansky,encryption%20keys%20to%20the%20FSB.">Russia blocks telegram</a>, <a href="https://en.wikipedia.org/wiki/Great_Firewall">Great Chinese Firewall</a>) — they can issue an order to restrict you too. Maybe you know the government that can be fully trusted? Tell me which one, and I’m packing my suitcases.</p><p>Or there’s a bug, good luck reaching support of Gmail, Instagram or Amazon.</p><p>Right for a true digital ownership — that’s what crypto solves. For the first time you are able to own digital good in a way that cannot be taken from you without an explicit permission. It can only be taken from you physically, by either stealing the key to your digital good or by making you give it somehow. Crypto assets are same as a physical goods that are protected firstly by your own force and in some places, may be, by an authority but existing in a digital space. And this is really the best it can get in a modern world.</p><p>How exactly does it work? This problem was solved by someone called Satoshi Nakamoto in 2009. The creator of Bitcoin. I won’t go into much details, just say that it’s working by removing a central trusted authority and replacing it with trust to every individual participating in the system. In other words instead of trusting google or amazon servers you trust everyone who “plays Bitcoin game”. How can you trust them? You trust, because you can only play bitcoin game with those who choose to play the same rules as you. It’s mathematically guaranteed — when you join the game you choose what algorithm to play on and all the gamers are restricted by it’s rules. This is code, not words, not laws, not constitution and it cannot be ever changed by anyone. When it’s changed it’s called bitcoin 2 and you can choose whether you want to play bitcoin 2 or you want to stay on bitcoin 1.</p><p>If you want to learn little bit more about fundamental problem which is solved by bitcoin watch <a href="https://www.youtube.com/watch?v=dfsRQyYXOsQ&amp;ab_channel=MarkReddick">this</a> or any other video on Byzantine Generals problem.</p><h3>Outro</h3><p>Lastly crypto is known for it’s crazy prices swings, scams and conspiracy theories. But actually it is the biggest innovation and a breakthrough technology that humanity seen in centuries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/0*yiR6peVcEwXUJaQs.jpeg" /></figure><p>With that I want to inspire everyone to learn about it. The simplest way is to invest a little bit of money and start following development of crypto, crypto services and innovations. Yes, there are crazy price swings, there is too much information and there’s too many scams. Be careful, be patient, be slow. But do progress, do not ignore it. Ask questions and learn. I’m very happy to help you, talk to you and answer your questions.</p><p>Financial application is the first real crypto application. But it’s not the only one. True ownership will be extended to every single corner of the digital world. And if not — I refuse to believe in such a future. I don’t want to live in the world when all my moves are watched, recorded and evaluated by a big brother, when I don’t have rights and don’t truly own anything.</p><p>To recap:</p><p>1. Life more and more moves into a digital space</p><p>2. Crypto solves true ownership in digital space</p><p>3. Crypto is not about getting rich, money or scams but today it’s mostly used for it</p><p>4. It’s important to start learning about crypto asap or we can be doomed into centralized anti-utopian future</p><p>Start learning more here:</p><ul><li>From political perspective: <a href="https://www.youtube.com/watch?v=T2zH-T_hmLs&amp;t=19s&amp;ab_channel=Internetstiftelsen">https://www.youtube.com/watch?v=T2zH-T_hmLs&amp;t=19s&amp;ab_channel=Internetstiftelsen</a></li><li>Video on two generals problem. Good for better understanding of Byzantine generals problem <a href="https://www.youtube.com/watch?v=s8Wbt0b8bwY&amp;ab_channel=Finematics">https://www.youtube.com/watch?v=s8Wbt0b8bwY&amp;ab_channel=Finematics</a></li><li>Non financial applications of crypto: <a href="https://qualitance.com/blog/non-financial-blockchain-applications/">https://qualitance.com/blog/non-financial-blockchain-applications/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f51bda44a67" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>