### Download Gotgbot Library Source: https://github.com/paulsonoflars/gotgbot/blob/v2/README.md Use this command to download the library using the standard Go get command. ```bash go get github.com/PaulSonOfLars/gotgbot/v2 ``` -------------------------------- ### Setup ngrok for Webhook Development Source: https://github.com/paulsonoflars/gotgbot/blob/v2/samples/README.md Instructions for setting up ngrok to tunnel HTTP traffic for webhook development. This command forwards traffic to port 8080. ```bash ngrok http 8080 ``` -------------------------------- ### Validate Telegram Init Data with Backend Source: https://github.com/paulsonoflars/gotgbot/blob/v2/samples/webappBot/index.html For any input, always pass the initData string, which will be validated by the backend. This example uses fetch to send the data and display the result. ```javascript // For any input, we must always pass the initData string, which will be validated by the backend. fetch("{{ .WebAppURL }}/validate", { headers: { "X-Auth": Telegram.WebApp.initData } }).then(function (response) { return response.text(); }).then(function (text) { document.getElementById("valid").innerHTML = "result: " + text; }).catch(function () { console.log("Booo"); }); ``` -------------------------------- ### Run Webapp Bot Source: https://github.com/paulsonoflars/gotgbot/blob/v2/samples/README.md Demonstrates how to serve a webapp using the gotgbot library. Requires setting URL and TOKEN environment variables. Recommended for development with ngrok. ```bash URL="" TOKEN="" go run . ``` -------------------------------- ### Run Echo Webhook Bot Source: https://github.com/paulsonoflars/gotgbot/blob/v2/samples/README.md Demonstrates how to run an echo bot using webhooks. Requires setting a TOKEN, WEBHOOK_DOMAIN, and WEBHOOK_SECRET environment variables. Recommended for development with ngrok. ```bash TOKEN="" WEBHOOK_DOMAIN="" WEBHOOK_SECRET="" go run . ``` -------------------------------- ### Initialize and Display Telegram User Data Source: https://github.com/paulsonoflars/gotgbot/blob/v2/samples/webappBot/index.html Use Telegram.WebApp.ready() to ensure the frontend is ready. Display 'unsafe' data directly, but always validate input data on the backend. ```javascript Telegram.WebApp.ready() // The frontend is OK displaying "unsafe" data, as long as we only use it for display reasons, and not as input. document.getElementById("name").innerHTML = "your name is: " + Telegram.WebApp.initDataUnsafe.user.first_name document.getElementById("id").innerHTML = "your id is: " + Telegram.WebApp.initDataUnsafe.user.id ``` -------------------------------- ### Regenerate Library Code Source: https://github.com/paulsonoflars/gotgbot/blob/v2/README.md Run 'go generate' from the repository root to regenerate the library code from the specification. To upgrade the commit in 'spec_commit' and regenerate, use 'GOTGBOT_UPGRADE=true go generate'. ```bash go generate ``` ```bash GOTGBOT_UPGRADE=true go generate ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.