soumyadeepdas/TbhRichBotPublic · Community Store Listing

Rich Message Demo [TBH]

ProfileTelegram
17 commands0 envUpdated 5d agoCreated Jul 16, 2026
Back to folder

commands/_richStreaming.js

javascript · 247 lines · click line # to share

1/**#command2name: /richStreaming3answer: 4keyboard: 5parse_mode: 6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12const draftId = String(Date.now());13 14// ==========================================15// Draft #1 - Thinking Phase16// ==========================================17const richContent = `18<h1>AI Assistant</h1>19 20<tg-thinking>21🧠 Analyzing request and collecting information...22</tg-thinking>23 24<h3>Reasoning Pipeline</h3>25 26<ul>27<li>User prompt received</li>28<li>Context retrieved</li>29<li>Documentation reviewed</li>30<li>Generating structured response</li>31</ul>32 33<hr/>34 35<h3>Current Analysis</h3>36 37<blockquote>38The system is evaluating available information and preparing a response.39<cite>AI Reasoning Engine</cite>40</blockquote>41 42<p>43Streaming drafts allow users to see intermediate progress while the final response is being generated.44</p>45 46<hr/>47 48<h3>Knowledge Sources</h3>49 50<ol>51<li>Telegram Bot API Documentation</li>52<li>Rich Message Specification</li>53<li>Formatting Reference</li>54</ol>55 56<hr/>57 58<h3>Working Notes</h3>59 60<pre><code class="language-javascript">61// Retrieve context62const context = getContext();63 64// Generate response65const response = generate(context);66</code></pre>67 68<hr/>69 70<h3>Mathematical Processing</h3>71 72<tg-math-block>73\\int_{0}^{1} x^2 dx = \\frac{1}{3}74</tg-math-block>75 76<hr/>77 78<h3>Reasoning Progress</h3>79 80<details open>81<summary>Show Progress</summary>82 83<p>✓ Context Retrieved</p>84<p>✓ Sources Indexed</p>85<p>⏳ Generating Response</p>86 87</details>88 89<footer>90⚡ Draft Preview • Generation in progress91</footer>92`;93 94Api.call("sendRichMessageDraft", {95  chat_id: chat.chatid,96  draft_id: draftId,97  rich_message: { html: richContent }98});99 100// Sleep for 2 seconds before the next update101await sleep(10000)102 103// ==========================================104// Draft #2 - Partial Response105// ==========================================106const updrich = `107<h1>AI Assistant</h1>108 109<tg-thinking>110🧠 Finalizing response...111</tg-thinking>112 113<h3>Generated Content</h3>114 115<p>116Telegram Rich Messages introduce a structured document format capable of rendering advanced layouts, references, media blocks, mathematical expressions, tables and interactive content.117</p>118 119<p>120Streaming drafts improve user experience by displaying temporary output while the final response is still being generated.121</p>122 123<hr/>124 125<h3>Features Detected</h3>126 127<ul>128<li>Rich Formatting</li>129<li>Tables</li>130<li>Media Blocks</li>131<li>References</li>132<li>AI Draft Streaming</li>133</ul>134 135<hr/>136 137<h3>Draft References</h3>138 139<p>140Telegram documentation141<a href="#ref1">[1]</a>142and rich message formatting143<a href="#ref2">[2]</a>.144</p>145 146<tg-reference name="ref1">147Telegram Bot API 10.1 Documentation148</tg-reference>149 150<tg-reference name="ref2">151Telegram Rich Message Formatting Specification152</tg-reference>153 154<footer>155⚡ Draft Updated • Final response incoming156</footer>157`;158 159Api.call("sendRichMessageDraft", {160  chat_id: chat.chatid,161  draft_id: draftId,162  rich_message: { html: updrich }163});164 165// Sleep for another 2 seconds before sending the final output166await sleep(10000)167 168// ==========================================169// Final Rich Message170// ==========================================171const finalRich = `172<h1>AI Streaming</h1>173 174<p>175This page demonstrates AI Draft Streaming introduced in Telegram Bot API 10.1.176</p>177 178<hr/>179 180<h3>What Was Demonstrated</h3>181 182<ul>183<li>Thinking Block</li>184<li>Draft Messages</li>185<li>Animated Draft Updates</li>186<li>Final Rich Message Delivery</li>187</ul>188 189<hr/>190 191<h3>Streaming Workflow</h3>192 193<ol>194<li>Draft Created</li>195<li>Thinking Block Displayed</li>196<li>Partial Response Generated</li>197<li>Final Rich Message Delivered</li>198</ol>199 200<hr/>201 202<h3>Example Generated Response</h3>203 204<blockquote>205Streaming drafts provide immediate feedback while AI systems continue generating responses in the background.206<cite>Telegram Bot API 10.1</cite>207</blockquote>208 209<hr/>210 211<h3>Mathematical Example</h3>212 213<tg-math-block>214E = mc^2215</tg-math-block>216 217<hr/>218 219<h3>Summary</h3>220 221<details open>222<summary>Expand Summary</summary>223 224<p>225AI Draft Streaming enables bots to provide a temporary preview of generated content before delivering the final rich message. This creates a faster and more interactive user experience.226</p>227 228</details>229 230<footer>231Bot API 10.1 • AI Streaming Demo232</footer>233`;234 235Api.call("sendRichMessage", {236  chat_id: chat.chatid,237  rich_message: { html: finalRich },238  reply_markup: {239    inline_keyboard: [240      [241        { text: "« Large Message", callback_data: "/richBigDocs" },242        { text: "Home", callback_data: "/start" },243        { text: "Showcase »", callback_data: "/richAll" }244      ]245    ]246  }247});