Skip to content

serejaris/telegram-skills / skills/tg-widgets

tg-widgets

Verified

Use when building or sending a Telegram message widget (HTML bubble, HTMLBubbles, `sendWidget`, `messageMediaWidget`, Bot API 10.4): an interactive HTML, CSS and JS program inside a chat bubble, such as a game, poll, calculator or live ticker. Teaches everything needed to write one: size, bubble, input, sandbox rules, state and requests, sending, and which chats accept a widget in production. Not for Mini Apps or Rich Messages.

examples/aquarium-pixel.html

View on GitHub
<style>body{margin:0}#e{position:relative;background:#0c3853}canvas{position:absolute;top:0;left:0;width:100%;height:100%;image-rendering:pixelated}</style><div id="e"><canvas id="b"></canvas><canvas id="f"></canvas></div><script>const t=window.TelegramWidget,o=document,f=t=>o.getElementById(t),e=Math.sin,c=Math.abs,n=Math.max,a=Math.min,r=Math.floor,s=f("e"),l=f("b"),h=f("f");let i;try{i=+localStorage.a}catch(t){}i=i||Date.now()%2e9+1;try{localStorage.a=i}catch(t){}const d=()=>(i=16807*i%2147483647)/2147483647;d(),d();const u=a(200,Math.ceil((s.clientWidth||360)/3)),y=Math.round(9*u/16);s.style.height=y*(s.clientWidth||360)/u+"px",l.width=h.width=u,l.height=h.height=y;const x=l.getContext("2d"),g=h.getContext("2d"),p=t=>[1,3,5].map(o=>parseInt(t.substr(o,2),16)),b=(t,o,f)=>(t=p(t),o=p(o),"#"+t.map((t,e)=>r(t+(o[e]-t)*f).toString(16).padStart(2,"0")).join("")),v=[0,8,2,10,12,4,14,6,3,11,1,9,15,7,13,5],m=(t,o)=>{const f=43758.5*e(12.9*(t+w)+78.2*o);return f-r(f)},M=(t,o)=>{const f=r(t),e=r(o),c=t-f,n=o-e;return(m(f,e)*(1-c)+m(f+1,e)*c)*(1-n)+(m(f,e+1)*(1-c)+m(f+1,e+1)*c)*n},S=["#2a8fa8","#2040c0","#109050","#6a2cb0","#c0506a","#d09030"][6*d()|0],w=99*d()|0,C=["#a8ead9","#6fd0c9","#42aebb","#2a8fa8","#1d7394","#165c7e","#104968","#0c3853","#092b42","#072134"].map(t=>b(t,S,.3)),R=["#0a1826","#14283a","#24404f","#3f5f68","#6f8c86","#a8bda6"],T=["#1c3f4c","#2f5f66","#4f8682","#7fae9b","#b5d2b4"].map(t=>b(t,S,.15)),A=[["#5a2c44","#b4545a","#e8846c","#ffc09a"],["#54401f","#a07c34","#e0bc5e","#fff0a4"],["#3e2a64","#7f4a9c","#bf70bc","#f4b4dc"]],E=t=>.86*y+1.2*e(.09*t)+1.4*e(.031*t+2),z=[.12,.45,.88,.66].map(t=>{const o=(t+.2*(d()-.5))*u;return[o,E(o)+3,(.14+.16*d())*u*.8,(.09+.12*d())*y]}),q={},F=(t,o,f,c,n,a)=>{for(let s=0;s<c;s++){t+=e(f),o-=Math.cos(f);const c=999*r(o)+r(t);q[c]=[a,n>1?1:n>0?2:3],q[c+1]=q[c+1]||[a,n>1?0:1]}n>0&&(F(t,o,f-.45-.3*d(),.8*c,n-1,a),F(t,o,f+.45+.3*d(),.8*c,n-1,a))};for(let t=3+3*d()|0;t--;){const t=d()*u;F(t,E(t)-1,0,3+1.5*d(),3,3*d()|0)}const I=(t,o,f,e)=>y*o+M(t*f,e)*y*.2;function O(t,o){return o/y*8.6-1.4*Math.exp(-(((t-.55*u)/u/.4)**2))*(1-o/y)}function P(t,o){const f=((t,o)=>v[t%4+o%4*4]/16)(t,o),c=q[999*o+t];if(c)return A[c[0]][c[1]];if(o>=E(t)){const c=.55*(1-(o-E(t))/11)+.14*e(.5*t+1.8*o+5*M(.1*t,.2*o))+.1;return T[n(0,a(4,r(5*c+f)))]}for(const e of z){const c=(t-e[0])/e[2],s=(o-e[1])/e[3];if(c*c+s*s<1){const e=.5-.32*c-.62*s+.5*(M(.3*t,.3*o)-.5);return R[n(0,a(5,r(5*e+f)))]}}return o>I(t,.72,.04,1)?b(C[8],C[9],o%3*.2):o>I(t,.56,.03,5)?C[a(9,r(O(t,o)+1.2+f))]:C[n(0,a(9,r(O(t,o)+f)))]}let W=0;!function t(){const o=a(y,W+24);for(;W<o;W++){let t=0,o=P(0,W);for(let f=1;f<=u;f++){const e=f<u?P(f,W):0;e!=o&&(x.fillStyle=o,x.fillRect(t,W,f-t,1),t=f,o=e)}}W<y&&setTimeout(t)}();const j=[[.46,["#7a2d12","#b84a14","#e8701c","#f79a3c","#ffc98a"],(t,o)=>c(t-.36)<.08||c(t+.22)<.08?"#f6f4ea":0,0],[.5,["#0f2a78","#1a45b8","#2a6ae8","#4f95f5","#a8d6ff"],(t,o)=>c(o+.05+.1*t)<.07&&t<.4?"#0b1a40":0,"#f2c82a"],[.66,["#8a6a10","#c9a018","#f2c82a","#fbe25a","#fff4a8"],()=>0,0],[.72,["#4a5a6a","#8a9aa6","#c8d2d6","#e8eeee","#ffffff"],t=>e(10*t+1)>.62?"#1c2a3a":0,0],[.34,["#6a2a5a","#a83f86","#d9629f","#ef93bf","#ffd5e4"],()=>0,0]];function k(t,o,f){const s=f<1?.75*(1-f):0,l=[];for(let f=-1;f<2;f++){const h=[],i=r(o*(t[0]+.4))+1;for(let l=-i;l<=i;l++){let i=0,d=0;for(let u=-r(1.7*o);u<=r(1.1*o)+1;u++){const y=u/o,x=l/o+.03*e(2*y+f)*(1-y);let g=0;if(c(y)<1){const o=t[0]*Math.sqrt(1-y*y)*(1+.2*y);if(c(x)<o){const f=.66-x/o*.5+.1*y;g=t[2](y,x)||t[1][n(0,a(4,r(5*f)))]}else x<0&&y>-.6&&y<.35&&x>-o-.2*(1-2*c(y+.1))?g=t[1][1]:x>0&&c(y+.15)<.28&&x<o+.13&&(g=t[1][0])}if(y<-.8){const o=-y-.8,e=x-f*o*.3;o<.62&&c(e)<.95*o+.07&&!(o>.42&&c(e)<.1)&&(g=t[3]||t[1][e<0?2:1])}g&&s&&(g=b(g,"#165c7e",s)),g!=i&&(i&&h.push([d,l,u-d,i]),i=g,d=u)}i&&h.push([d,l,r(1.1*o)+2-d,i])}const d=r(.58*o),u=-r(o*t[0]*.28)-(o>9?1:0);h.push([d,u,o>7?2:1,"#0a0f18"]),o>9&&h.push([d+1,u,1,"#fff"]),l.push(h)}return l}const B=Array.from({length:4+3*d()|0},()=>{const t=[1,.8,.45][3*d()|0];return[5*d()|0,t*(8+2.5*d()),t]}).map(t=>({x:d()*u,y:10+d()*y*.4,vx:d()<.5?-5:5,vy:0,dr:1,w:9*d(),s:t[1]*u/130,z:t[2],o:9*d(),P:k(j[t[0]],t[1]*u/130,t[2])})).sort((t,o)=>t.z-o.z),L=Array.from({length:14},(t,o)=>({x:d()*u,y:.2*y+d()*y*.2,vx:0,vy:0,o:o,r:4+12*d()})),D=[],G=[],H=Array.from({length:4+4*d()|0},(t,o)=>[d(),.25+.25*d(),o,d()<.5]).map(t=>({x:t[0]*u,h:t[1]*y*.72+6,o:t[2],c:t[3]?["#0d3f55","#126078"]:["#0e5a48","#23915f","#4cc47e"]})),X=g.createLinearGradient(0,0,0,.78*y);X.addColorStop(0,"rgba(200,255,235,.13)"),X.addColorStop(1,"rgba(200,255,235,0)");const Y=(t,o,f,e,c)=>{g.fillStyle=t,g.fillRect(0|o,0|f,e,c)},J=(t,o,f,e)=>{g.fillStyle=e,[...t].forEach((t,e)=>{const c="АКВРИУМ.ЕХОЫБП".indexOf(t);if(c>=0){const t=parseInt("ehvhhhisihuhuhuuhugghjlphhhf1uhrlhh00004vgugvha4ahehhhehhtltvguhuvhhhh".substr(5*c,5),32);for(let c=0;c<25;c++)t>>24-c&1&&g.fillRect(o+6*e+c%5,f+r(c/5),1,1)}})};function K(t,o){const f=E(t.x)+1;for(let n=0;n<t.h;n++){const a=t.x+e(.1*n+.7*o+t.o)*n*.07+.9*e(.3*n+1.3*o+t.o),r=f-n,s=c(e(.42*n+2*t.o));Y(t.c[0],a,r,3,1),Y(t.c[1],a,r,2,1),t.c[2]&&s>.86&&Y(t.c[2],a+(n%2?3:-2),r,2,1)}}const N=t=>{let o,f=1e9;for(const e of D){const c=(e.x-t.x)**2+(e.y-t.y)**2;c<f&&(f=c,o=e)}return o},Q=(t,o,f,e,c,n)=>{const a=o-t.x,r=f-t.y,s=Math.hypot(a,r)||1;t.vx+=(a/s*e-t.vx)*c*n,t.vy+=(r/s*e-t.vy)*c*n,t.x+=t.vx*n,t.y+=t.vy*n};let U=0,V=0,Z=0;s.addEventListener("click",o=>{const f=s.getBoundingClientRect(),e=(o.clientX-f.left)/f.width*u,c=(o.clientY-f.top)/f.height*y;Z=0;for(let t=0;t<7;t++)D.push({x:e+14*(d()-.5),y:c+3*d(),v:4+4*d(),o:9*d()});t&&t.HapticFeedback.selectionChanged()}),requestAnimationFrame(function t(o){if(requestAnimationFrame(t),o-U<66)return;const f=a((o-U)/1e3,.2),s=o/1e3;if(U=o,Z+=f,function(t,o){V+=t;const f=u/2+e(.19*V)*u*.36,r=.32*y+e(.31*V)*y*.1;for(const f of D)f.y+=f.v*t,f.x+=e(2*o+f.o)*t*2,f.y>.7*y&&D.splice(D.indexOf(f),1);for(const o of B){const f=N(o);if(f)Q(o,f.x,f.y,30,2.2,t),c(f.x-o.x-o.dr*o.s*.6)<.6*o.s&&c(f.y-o.y)<.35*o.s+1&&D.splice(D.indexOf(f),1);else{o.w+=(d()-.5)*t*1.5;let f=o.x+40*Math.cos(o.w),c=o.y+12*e(o.w);o.x<2*o.s&&(f=u),o.x>u-2*o.s&&(f=0),o.y<9&&(c=y),o.y>.62*y&&(c=0),Q(o,f,c,6+5*o.z,.6,t)}for(const f of B)if(f!=o){const e=o.x-f.x,r=o.y-f.y,s=o.s+f.s;c(e)<1.1*s&&c(r)<.75*s&&(o.y=n(8,a(.72*y,o.y+(r<0?-1:1)*t*16)),o.x+=(e<0?-1:1)*t*7)}c(o.vx)>.5&&(o.dr+=((o.vx>0?1:-1)-o.dr)*a(1,3*t)),c(o.dr)<.05&&(o.dr=.05)}for(const o of L)Q(o,f+e(V+o.o)*o.r*1.5,r+e(1.3*V+2*o.o)*o.r*.5,17,1.8,t);d()<1.6*t&&G.push({x:.46*u+3*d(),y:E(.46*u)-8,r:d(),o:9*d()});for(const o of G)o.y-=(9+9*o.r)*t,o.x+=e(.2*o.y+o.o)*t*3;G.splice(0,G.length,...G.filter(t=>t.y>2))}(f,s),function(t){g.clearRect(0,0,u,y),g.fillStyle=X;for(let o=0;o<5;o++){const f=u*(.26*o-.08)+7*e(.13*t+2*o),c=7+o%3*5,n=6*e(.21*t+o);g.beginPath(),g.moveTo(f,0),g.lineTo(f+c,0),g.lineTo(f+2*c+26+n,.78*y),g.lineTo(f+16+n,.78*y),g.fill()}H.forEach(o=>{null==o.c[2]&&K(o,t)});for(const o of B){const f=o.P[1+Math.round(e(t*(o.vx*o.vx>30?12:5)+o.o))],a=o.dr<0?-1:1,r=.8*c(o.dr)+.2,s=0|o.x,l=0|o.y;for(const t of f){const o=a>0?t[0]:-t[0]-t[2];g.fillStyle=t[3],g.fillRect(s+Math.round(o*r),l+t[1],n(1,Math.round(t[2]*r)),1)}}for(const t of L)Y("#9ff0ff",t.x,t.y,2,1);for(const t of D)Y("#ffd9a0",t.x,t.y,1,1);H.forEach(o=>{o.c[2]&&K(o,t)});for(const t of G){const o=t.r>.7?2:1;Y("rgba(235,255,250,.75)",t.x,t.y,o,o)}}(s),Z>8){const t=.3*y|0;Y("#000",0,t,u,.42*y),J("АКВАРИУМ.ЕХЕ",(u-71)/2|0,t+6,"#ffc98a"),r(3*s)%2&&J("ПОКОРМИ РЫБОК",(u-77)/2|0,t+18,"#fff")}}),t&&t.ready();
</script>
brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 322kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 198kUpdated Claude CodeCodexVerifiedInstall