TBC Libraries (Libs)
Libraries, often called libs, in Telebot Creator (TBC) enhance the basic TPY functionalities by offering pre-built modules for specific tasks. These libraries make it easier and faster to add advanced features to your Telegram bots, such as handling payments, managing blockchain transactions, working with data, generating random values, and more.
5.1 Overview of Libraries
TBC libraries are grouped based on their functionalities to help you develop bots efficiently:
Payment Integrations: Automate payments using popular services.
Blockchain Transactions: Manage cryptocurrency transfers and transactions.
Data Handling: Work with data easily using CSV files.
Randomization: Generate random numbers or strings for games and giveaways.
Resource Management: Track points, credits, or other resources for users or globally.
5.2 Key Libraries and Their Functions
Here are the main libraries available in TBC, along with their key functions and examples of how to use them:
1. libs.ARB
Handles transactions on the Arbitrum (ARB) blockchain.
Functions:
setKeys(private_key)
: Sets your private key for ARB transactions.send(value, to, contract, private_key=None)
: Sends tokens via a contract.sendARB(value, to, private_key=None)
: Sends ARB cryptocurrency.
Example:
2. libs.CSV
Simplifies data management with CSV files.
Class:
CSVHandler(filename)
: Manages a specific CSV file.
Methods:
create_csv(headers)
: Creates a new CSV file with headers.add_row(row)
: Adds a new row of data.edit_row(row_index, row)
: Edits an existing row.get()
: Retrieves information about the CSV file.delete()
: Deletes the CSV file.
Example:
3. libs.Coinbase
Integrates with the Coinbase payment gateway for cryptocurrency transactions.
Functions:
setKeys(api_key, secret)
: Sets your Coinbase API keys.post(api_key=None, secret=None)
: Returns a Coinbase client instance.
Example:
4. libs.Crypto
Provides tools for cryptocurrency conversions and pricing.
Functions:
convert(_from, _to, _amount)
: Converts an amount from one cryptocurrency to another.get_price(currency, price_in)
: Gets the current price of a cryptocurrency.
Example:
5. libs.Random
Generates random numbers and strings for various uses.
Functions:
randomInt(min, max)
: Returns a random integer between min and max.randomStr(length, char_set=None)
: Returns a random string of the specified length.randomFloat(min, max)
: Returns a random float between min and max.randomAscii(length)
: Returns a random ASCII string.
Example:
6. libs.Polygon
Supports transactions on the Polygon blockchain.
Functions:
setKeys(private_key)
: Sets your private key for Polygon transactions.send(value, to, contract, private_key=None)
: Sends tokens via a contract.sendPolygon(value, to, private_key=None)
: Sends MATIC tokens.
Example:
7. libs.Resources
Manages numeric values tied to users or globally for tracking points or credits.
Classes:
userRes(name, user)
: Manages resources for a specific user.globalRes(name)
: Manages global resources.
Methods:
value()
: Gets the current value.add(amount)
: Adds to the resource.cut(amount)
: Subtracts from the resource.set(amount)
: Sets the resource to a specific value.reset()
: Resets the resource to zero.getAllData(length)
: Retrieves top resource entries.
Example:
8. libs.Paytm
Integrates with the Paytm payment gateway for fund transfers and automated payments.
Functions:
setKeys(key, mid, token)
: Sets your Paytm merchant credentials.send(amount, number, description=None, key=None, mid=None, token=None)
: Sends a payment to a phone number.
Example:
9. libs.TTcoin
Handles transactions using TTcoin cryptocurrency.
Functions:
setKeys(private_key)
: Sets your TTcoin private key.sendTT(value, to, private_key=None)
: Sends TTcoin to an address.
Example:
10. libs.Tomochain
Supports transactions on the Tomochain network.
Functions:
setKeys(private_key)
: Sets your Tomochain private key.sendTRC20(value, to, contract, private_key=None)
: Sends TRC20 tokens.sendTomochain(value, to, private_key=None)
: Sends TOMO coins.
Example:
11. libs.Webhook
The libs.Webhook
library in Telebot Creator allows you to create and manage webhooks for seamless external integrations. Webhooks enable bots to respond to real-time updates from external systems, such as payment notifications or user actions.
Functions
getUrlFor(command, user_id=None, chat_id=None, bot_id=None, api_key=None, **options)
Description: Generates a webhook URL for invoking a specific command, optionally tied to a specific user, chat, or another bot.
Function Syntax:
Parameters:
command
(str): The command to be triggered by the webhook.user_id
(Optional[str]): The user ID associated with the webhook.chat_id
(Optional[str]): The chat ID associated with the webhook.bot_id
(Optional[str]): The ID of the bot for which the webhook is being generated. If provided,api_key
is required.api_key
(Optional[str]): The API key of the bot owner. Used for validation whenbot_id
is specified.**options
: Additional options to customize the webhook behavior.
In webhook commands, the incoming response data is stored in
options
, notmessage
. Theoptions
dictionary includes two keys:data
: The raw incoming data.json
: A parsed JSON object from the webhook payload.
Examples:
Basic Webhook URL:
Webhook for Another Bot:
Webhook with Additional Options:
Use Cases
Payment Confirmation: Generate webhook URLs for real-time payment updates from external systems.
Bot-to-Bot Communication: Use
bot_id
andapi_key
to enable bots to trigger commands in each other.Dynamic Event Handling: Pass additional options to customize webhook behavior based on the event.
12. libs.DateAndTime
Works with dates and times.
Functions:
utcnow()
: Gets the current UTC date and time.date_now()
: Gets the current UTC date.time()
: Gets the current UNIX timestamp.now(timezone_str)
: Gets the current date and time in a specific timezone.
Example:
13. libs.Oxapay
Integrates the Oxapay payment system for merchants.
Functions:
post(merchant_api_key)
: Initializes the Oxapay client with your API key.
Example:
14. libs.customHTTP
Performs HTTP requests with limitations on data size and timeouts, we use it as HTTP class but if you want you can use this lib, this lib provides 30 seconds timeout and it can receive contene upto 20 mb.
Class:
CustomHTTP()
: Creates an HTTP client.
Methods:
get(url, **kwargs)
: Performs a GET request.post(url, **kwargs)
: Performs a POST request.put(url, **kwargs)
: Performs a PUT request.head(url, **kwargs)
: Performs a HEAD request.options(url, **kwargs)
: Performs an OPTIONS request.patch(url, **kwargs)
: Performs a PATCH request.close()
: Closes the HTTP session.
Example:
15. libs.web3lib
Enables transactions on Ethereum-compatible blockchains.
Functions:
setKeys(private_key)
: Sets your private key for web3 transactions.sendETHER(value, to, contract, rpc_url, gasPrice=None, private_key=None)
: Sends tokens on an Ethereum network.sendPolygon(value, to, private_key=None)
: Sends MATIC tokens.
Example:
5.3 Example Use Cases for Libraries
Here are some real-world scenarios where these libraries can be applied:
Payment Automation
Automate payments for subscriptions or services using payment libraries.
Example:
User Data Tracking
Manage user data for referral systems or leaderboards with the CSV library.
Example:
Crypto Payment Bots
Handle cryptocurrency transactions for services or rewards using blockchain libraries.
Example:
Random Giveaways
Use the Random library to create giveaways or dynamic responses.
Example:
Webhook Integrations
Connect your bot with external services using the Webhook library.
Example:
5.4 Additional Libraries
Here are the remaining libraries available in TBC:
libs.TTcoin
Handles TTcoin cryptocurrency transactions.
Functions:
setKeys(private_key)
: Sets your TTcoin private key.sendTT(value, to, private_key=None)
: Sends TTcoin to an address.
Example:
libs.Tomochain
Supports Tomochain network transactions.
Functions:
setKeys(private_key)
: Sets your Tomochain private key.sendTRC20(value, to, contract, private_key=None)
: Sends TRC20 tokens.sendTomochain(value, to, private_key=None)
: Sends TOMO coins.
Example:
libs.web3lib
Enables Ethereum-compatible blockchain transactions.
Functions:
setKeys(private_key)
: Sets your private key.sendETHER(value, to, contract, rpc_url, gasPrice=None, private_key=None)
: Sends Ether or tokens.sendPolygon(value, to, private_key=None)
: Sends MATIC tokens.
Example:
5.5 Summary of Libraries
Library
Purpose
Key Functions
libs.ARB
Arbitrum blockchain transactions
setKeys
, send
, sendARB
libs.CSV
Data management with CSV files
create_csv
, add_row
, edit_row
, get
, delete
libs.Coinbase
Coinbase payment integration
setKeys
, post
libs.Crypto
Cryptocurrency conversions and pricing
convert
, get_price
libs.Random
Generating random numbers and strings
randomInt
, randomStr
, randomFloat
, randomAscii
libs.Polygon
Polygon blockchain transactions
setKeys
, send
, sendPolygon
libs.Resources
Managing user and global resources
value
, add
, cut
, set
, reset
, getAllData
libs.Paytm
Paytm payment integration
setKeys
, send
libs.TTcoin
TTcoin cryptocurrency transactions
setKeys
, sendTT
libs.Tomochain
Tomochain network transactions
setKeys
, sendTRC20
, sendTomochain
libs.Webhook
Creating and managing webhooks
genRandomId
, getUrlFor
libs.DateAndTime
Working with dates and times
utcnow
, date_now
, time
, now
libs.Oxapay
Oxapay payment integration
post
libs.customHTTP
Performing HTTP requests with constraints
get
, post
, put
, delete
, head
, options
, patch
, close
libs.web3lib
Ethereum-compatible blockchain transactions
setKeys
, sendETHER
, sendPolygon
5.6 Real-World Applications of Libraries
Here are some practical examples of how you can use these libraries in your bots:
Crypto Payment Bots
Handle cryptocurrency payments for services or rewards.
Example:
Referral and Loyalty Systems
Manage user points or rewards for referrals and other actions.
Example:
Data-Driven Decisions
Log and analyze user data or create leaderboards using CSV files.
Example:
Automated Payments
Use Paytm or Coinbase libraries to automate payment transfers.
Example:
Random Giveaways
Create random giveaways or generate unique codes.
Example:
By using these libraries, you can significantly extend the capabilities of your Telegram bots, making them more interactive, efficient, and feature-rich. Whether you need to handle payments, manage data, or integrate with blockchain technologies, TBC’s libraries provide the tools you need to build powerful bots with ease.
Last updated