CodeTwig Examples
28 subscribers
2 files
Download Telegram
Channel created
This media is not supported in your browser
VIEW IN TELEGRAM
🔶 Simple "Hello World" Template

🆓 #Free

📝 What is this?
An example code you can copy to use in your templates.
If you send anything bot will answer "Hello World!"

{% do apiWebhook("sendMessage", {
"text": "Hello World!",
"chat_id": update.message.chat.id
}) %}
🔶 Send Message Full Example

🆓 #Free

📝 What is this?
An example template of a sendMessage with a lot of parameters.
If you send the bot /start it will answer a "Hello World" with buttons, reply, url, etc...

{% if update.message.text matches '/^\\/start\\b/' %}
{% do apiWebhook("sendMessage", {
"text": "Hello World!"|escape,
"chat_id": update.message.chat.id,
"message_thread_id": update.message.message_thread_id ?? false,
"parse_mode": "HTML",
"link_preview_options": {
"is_disabled": false,
"url": "https://files.catbox.moe/58uxa1.webp",
"prefer_small_media": true,
"prefer_large_media": false,
"show_above_text": false,
},
"disable_notification": false,
"protect_content": false,
"message_effect_id": "5046509860389126442",
"reply_parameters": {
"message_id": update.message.message_id ?? false,
"chat_id": update.message.chat.id,
"allow_sending_without_reply": true,
},
"reply_markup": {"inline_keyboard": [
[{"text": "Send me a message", "url": "https://t.me/CodeTwigBot?start"}],
[{"text": "Google", "url": "https://google.com"}, {"text": "Google", "url": "https://google.com"}]
]}
}) %}
{% endif %}
🔶 Send business message

🆓 #Free

📝 What is this?
An example template of a sendMessage using a business account.
If customer send a message with the expressions "menu" or "bill of fare" the bot answers with a menu.

{% if update.business_message.text matches '/\\b(menu|bill of fare)\\b/i'%}
{% do apiWebhook("sendMessage", {
"business_connection_id": update.business_message.business_connection_id,
"chat_id": update.business_message.chat.id,
"parse_mode": "HTML",
"text": "<b>The menu is:</b>
- Hamburguer ($10)
- Fries ($3)
- Soda ($2)

You can check the full menu in our website",
})%}
{% endif %}
Template
Template
Template
🔶 Example bot to receive donations using Telegram Stars

🆓 #Free or 🎁 #Donate

📝 What is this?
An example template of a bot that can receive donations.
The bot send invoices when someone send "/start", accept the payment if it is a "donation", notifies the bot creator of payments that were made.
The bot also has a command to refund the payments.

{# send the invoice #}
{% if update.message.text matches '/^\\/start$/i' %}
{% do apiWebhook("sendInvoice", {
"chat_id": update.message.chat.id,
"title": "Donation",
"description": "Donation to the developer of this bot.",
"payload": "donation",
"currency": "XTR",
"prices": [{
"label": "Buy",
"amount": 1
}]
}) %}
{% endif %}


{# confirm the donation #}
{% if update.pre_checkout_query.id is defined and update.pre_checkout_query.invoice_payload == "donation" %}
{% do apiWebhook("answerPreCheckoutQuery", {
"pre_checkout_query_id": update.pre_checkout_query.id,
"ok": true
}) %}
{% endif %}


{# send confirmation message to bot owner #}
{% if update.message.successful_payment is defined %}
{# set chat where to send the payment #}
{% if log_chat %}
{% set owner_chat = log_chat %}
{% else %}
{% set owner_chat = owner_id %}
{% endif%}

{% set resp = apiWebhook("sendMessage", {
"chat_id": owner_chat,
"text": "<u><b>New donation received!</b></u>

<b>User_id:</b> <a href=\"tg://user?id=#{update.message.from.id}\">#{update.message.from.id}</a>
<b>Username:</b> @#{update.message.from.username??"?"}
<b>Name:</b> #{update.message.from.first_name|escape}
<b>Currency:</b> <code>#{update.message.successful_payment.currency}</code>
<b>Total_amount:</b> <code>#{update.message.successful_payment.total_amount}</code>
<b>Invoice_payload:</b> <code>#{update.message.successful_payment.invoice_payload}</code>
<b>Telegram_payment_charge_id:</b> <code>#{update.message.successful_payment.telegram_payment_charge_id}</code>
<b>Provider_payment_charge_id:</b> <code>#{update.message.successful_payment.provider_payment_charge_id}</code>

To refund this payment put your token in the correct place and access the link bellow:
<code>https://api.telegram.botPUT_BOT_TOKEN_HERE/refundStarPayment?user_id=#{update.message.from.id}&amp;telegram_payment_charge_id=#{update.message.successful_payment.telegram_payment_charge_id}</code>

Or use the command bellow:
<code>/refund #{update.message.from.id} #{update.message.successful_payment.telegram_payment_charge_id}</code>
",
"parse_mode": "HTML",
}) %}

{# This message will only be sent if you have the Donation Plan #}
{% do apiNoResponse("sendMessage", {
"chat_id": update.message.from.id,
"text": "<b>Thanks!</b>
The developer received your donation of ⭐️ #{update.message.successful_payment.total_amount} Telegram Stars",
"parse_mode": "HTML",
"message_effect_id": "5046509860389126442",
}) %}

{% endif %}


{% if update.message.from.id == owner_id and update.message.text matches '/^\\/refund [0-9]+ [A-Za-z_0-9]+$/i' %}
{% set data = update.message.text|split(" ")%}
{% set resp = apiWebhook("refundStarPayment", {
"user_id": data.1,
"telegram_payment_charge_id": data.2
})%}

{# This message will only be sent if you have the Donation Plan #}
{% do apiNoResponse("sendMessage", {
"chat_id": update.message.from.id,
"text": "Payment was refunded.",
}) %}
{% endif %}
🤯1🎉1
🔶 Example bot to send and receive messages privately

🆓 #Free

📝 What is this?
An example template of a bot similar to Livegram that can send and receive messages from users privately.
The bot sends a info message when the user starts the bot.
The bot sends replies to info message to the user.
The bot check if the user blocked the bot and return an error.

{# set the chat to send the messages #}
{% set owner_chat = owner_id %}

{# answers to /start #}
{% if update.message.chat.type == "private" and update.message.text matches '/^\\/start$/i' %}
{% set resp = apiResponse("sendMessage", {
"text": "Send me messages and I will forward them to the owner of this bot.",
}) %}

{% do apiWebhook("sendMessage", {
"chat_id": owner_chat,
"text": "<b>ID:</b> <a href=\"tg://user?id=#{update.message.from.id}\">#{update.message.from.id}</a>
<b>Username:</b> @#{update.message.from.username??"?"}
<b>Name:</b> #{ update.message.from.last_name ? (update.message.from.first_name~update.message.from.first_name)|escape : update.message.from.first_name|escape }
<b>language_code:</b> #{update.message.from.language_code??"?"}

User sent /start to the bot.",
"parse_mode": "HTML"
}) %}

{# if owner replied a message, forward it to user #}
{% elseif update.message.chat.type == "private" and update.message.chat.id == owner_id and update.message.reply_to_message.from.id == bot_id %}
{% set data = update.message.reply_to_message.text|split("\n") %}
{% set id = data.0|split(": ") %}
{% set resp = apiResponse("copyMessage", {
"from_chat_id": owner_chat,
"message_id": update.message.message_id,
"chat_id": id.1,
"protect_content": false
}) %}

{# if there was an error sending the message, send error to owner #}
{% if resp.description is defined %}
{% do apiWebhook("sendMessage", {"text": "⚠️ "~resp.description}) %}
{% endif %}

{# if user sent a message, send to owner #}
{% elseif update.message.chat.type == "private" %}
{% set a = apiResponse("sendMessage", {
"chat_id": owner_chat,
"text": "<b>ID:</b> <a href=\"tg://user?id=#{update.message.from.id}\">#{update.message.from.id}</a>
<b>Username:</b> @#{update.message.from.username??"?"}
<b>Name:</b> #{ update.message.from.last_name ? (update.message.from.first_name~update.message.from.first_name)|escape : update.message.from.first_name|escape }
<b>language_code:</b> #{update.message.from.language_code??"?"}",
"parse_mode": "HTML"
}) %}
{% do apiWebhook("forwardMessage", {
"chat_id": owner_chat,
"from_chat_id": update.message.chat.id,
"message_id": update.message.message_id
}) %}

{% endif %}
👍1
NoelSpamBot v0.4.5.4.twig
312.1 KB
🔶 Full anti spam bot for groups

💎 Only #Premium can clone

📝 What is this?
T
emplate of @NoelSpamBot a bot that detects and remove spam in groups. Bot has a lot of anti-spam features like:
> Automatically delete, mute and report spammers to admins group.
> Automatically handle @admin or /report from members and report them to admins group.
> Check content of first X messages new users sent in the group.
> Check content of messages new users sent in the first X hours
> 2 anti-floods that also count message length and has temporary whitelist
> Check new users text messages, photos, stories, documents, forwards from channels/groups/users/self, usernames from channels/groups, inline bots, inline url keyboards, public and private links, referral links, urls shorteners, non-latin characters, all executable files, phone numbers, known crypto spam, known +18 spam, known sellers spam, external replies, etc.
> Analise long messages, messages with multiple emojis and messages with multiple line breakers.
BanVoucherBot v1.0.1.twig
26.8 KB
🔶 Bot that sell vouchers to mute/ban users in groups using Telegram Stars

🆓 All #Free accounts can clone

📝 What is this?
Template of @VoucherBanBot a bot that can sell to members of your group vouchers to mute and ban other users. Bot has a lot of features like:
> User can use the shop to buy mute and ban vouchers using Telegram stars ⭐️ using /shop
> Users can check all vouchers they have using /myvouchers
> Owner of the bot can give members vouchers for free (if they win a contest for example) using /add_voucher
> Owner of the bot can remove members vouchers using /remove_voucher
> Owner of the bot can easily refund payments using /refund