Adsun SDK integration guide
Integrate Adsun into a Telegram Mini App using the JavaScript SDK, or follow the bot-specific code supplied in your publisher workspace.

Use the integration code from your block
Open the publisher workspace, select your platform and ad block, then copy its integration code. The script loads from your configured backend API at /sdk.js. There is no universal SDK host assumed by this guide: use the address shown in your own block page.
Reward and Interstitial controllers
After the SDK script has loaded, initialize the controller with your block ID. Start with debug mode enabled for integration testing. Replace the block ID with your actual block and disable debug for production.
const controller = window.Adsun.init({
blockId: "YOUR_BLOCK_ID",
debug: true,
});
controller.addEventListener("onReward", () => {
// Refresh reward state from your own server.
});
controller.show().catch((result) => {
// Handle skips, unavailable ads and playback errors.
console.warn(result);
});Choose a Reward or Interstitial block in the workspace. onReward follows server-verified completion. Use the block’s server-to-server Reward URL for authoritative reward grants, with your own request validation and duplicate-safe handling; do not grant rewards from show().then() alone. Debug ads are not billed and do not call the production Reward URL.
Task blocks
Load the same SDK before using the custom element. Task blocks expose their own reward event and slot-based content.
<adsun-task data-block-id="YOUR_BLOCK_ID" data-debug="true">
<span slot="reward">Your in-app reward</span>
</adsun-task>
<script>
const task = document.querySelector("adsun-task");
task.addEventListener("reward", () => {
// Connect your app's reward handling here.
});
</script>Task blocks enforce a minimum time away before a reward claim and a delay before the next task; review the values configured on your block rather than assuming a universal timer. For advanced settings and the full event list, copy the “All options” example from your block page. Disable data-debug before production.
Telegram bot integrations
Bot blocks use a separate bot integration example and publisher account token. Copy these from the authenticated publisher workspace and keep tokens on your server. Do not place private account tokens in a public Mini App or this documentation.
Integration troubleshooting
- onBannerNotFound means no eligible ad was found; check demand, block status and frequency settings instead of immediately retrying.
- onNotSuitable can signal failed reward verification; do not issue an authoritative reward from a resolved promise.
- onSkip and onError require restoring the app interface without trapping the user.
- For task blocks use reward, leave and return events, not controller event names.
See rewarded ad integration safeguards and the bot-message delivery guide for format-specific behavior.
Before going live
- Confirm the SDK URL points to your deployed backend and returns JavaScript.
- Test completion, skip, no-ad and error outcomes without granting duplicate rewards.
- Check the block configuration and SDK health report.
- Disable test mode and review actual account reporting.