telegram-seller-sdk
v1.0.14
Published
JavaScript SDK for Telegram Seller Merchant API
Readme
Telegram Seller SDK
JavaScript SDK for Telegram Seller Merchant API
安装
npm install telegram-seller-sdk
# 或
yarn add telegram-seller-sdk文件上传
- client.file.upload(file, object)
Auth模块
-ahth.login(object)
- auth.lougout()
Merchant模块
- merchant.getMe()
- merchant.getConfigs(object)
- merchant.getConfig(id)
- merchant.getLanguages()
User模块
- user.getUsers(object)
- user.getUser(id)
- user.getRecharges(object)
- user.getRecharge(id)
- user.getRecharges(object)
- user.getRecharge(id)
- user.getWalletLogTypes()
- user.getWalletLogs(object)
- user.getWalletLog(id)
Product模块
分组
- client.product.getTypes()
- client.product.createGroup(name, object)
- client.product.getGroups(object)
- client.product.getGroup(id)
client.product.createGroup({
type: "telegram_account",
name:"TEST GROUP",
bot_data: {
type: "text",
'en': {'text': '🌏 测试分组123', 'file_id': ''},
'zh-hans': {'text': '🌏 TEST GROUP123', 'file_id': ''},
}
})
client.product.create({
type: "telegram_account",
name:"TEST Product",
group_id: 38,
price: 1.01,
bot_data: {
type: "text",
'en': {'text': '🌏 测试商品123', 'file_id': ''},
'zh-hans': {'text': '🌏 TEST product123', 'file_id': ''},
}
})
商品
- client.product.createGroup(name, object)
- client.product.getProducts(object)
- client.product.getProduct(id)
商品资源
- client.product.getResources(object)
- client.product.getResource(id)
- client.product.createTelegramAccountResouce(object)
- client.product.downloadTelegramAccountResouce(object)
后台任务
- client.task.getTasks(object)
- client.task.getTask(id)
订单
- client.order.getOrders(object)
- client.order.getOrder(id)
使用示例
const TelegramSellerSDK = require('telegram-seller-sdk');
初始化SDK
const sdk = new TelegramSellerSDK({
baseURL: 'http:66.42.55.5:8000/telegram-seller/merchant-api/'
});
登录
async function login() {
try {
const result = await sdk.auth.login({
username: 'admin',
password: "O8UX/awQKxmYTPx2on58sA=="
});
} catch (error) {
console.error('Login failed:', error.message);
}
}
获取商品列表
async function getProducts() {
try {
const { data } = await sdk.product.list({
page: 1,
size: 10,
status: 'active'
});
console.log('Products:', data);
} catch (error) {
console.error('Failed to get products:', error.message);
}
}
// 上传账户
async function createTelegramAccountResouce() {
try {
const { data } = await sdk.product.createTelegramAccountResouce({
product_id: 1,
file: "./file.zip" // 上传返回的路径
});
console.log('Products:', data);
} catch (error) {
console.error('Failed to createTelegramAccountResouce:', error.message);
}
}
// 下载账户
async function downloadTelegramAccountResouce() {
try {
const { data } = await sdk.product.downloadTelegramAccountResouce({
ids: [1,2,3]
});
console.log('Products:', data);
} catch (error) {
console.error('Failed to downloadTelegramAccountResouce:', error.message);
}
}