Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 2 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
# BBPointBot - chat bot
It is repository for chat bot: [@BBPointBot](https://t.me/BBPointBot)

I am BB point bot. I am under development.⚒

:gem: - it is BB Point.

You can spend it:
- for iterations
- for discount
- for good help from admin

All conditions will be later!
Just start collecting thems!

You can get :gem::
- for good answer and help in BB chat

![](https://i.imgur.com/fw7HmsG.png)


# NewBBPointBot - chat bot
It is repository for chat bot: [@NewBBPointBot](https://t.me/NewBBPointBot)

## What it is?
This repository can be imported to [Bots.Business](https://bots.business) as a worked chat bot.
Expand Down
4 changes: 2 additions & 2 deletions bot.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"bb_sync_version":"1.0",
"name":"BBPointBot",
"name":"NewBBPointBot",
"csv_url":null,
"git_remote":"git@github.com:bots-business/BBPointBot.git"
"git_remote":"git@github.com:abhijeetpatil2122/BBPointBot"
}
173 changes: 108 additions & 65 deletions commands/@.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,138 @@
/*CMD
command: @
help:
need_reply:
need_reply: false
auto_retry_time:
folder:
answer:
keyboard:

<<ANSWER

ANSWER

<<KEYBOARD

KEYBOARD
aliases:
group:
CMD*/

function isAdmin(){
var admin_id = AdminPanel.getFieldValue({
panel_name: "AdminInfo", // panel name
field_name: "ADMIN_ID" // field name
// Command: @

// Check if current user is the main bot admin
function isAdmin() {
const admin_id = AdminPanel.getFieldValue({
panel_name: "AdminInfo",
field_name: "ADMIN_ID"
})
return user.id == admin_id
return user && parseInt(admin_id, 10) === user.id
}

function isNumeric(value){
return value.match(/^-{0,1}\d+$/)
// Validate numeric value
function isNumeric(value) {
return /^-?\d+$/.test(value)
}

function broadcastToChanell(text){
var chanell = AdminPanel.getFieldValue({
panel_name: "Options", // panel name
field_name: "InfoChannel" // field name
})

Api.sendMessage({ chat_id: chanell, text: text } );
// Escape HTML special characters
function escapeHTML(str) {
if (!str) return ""
return String(str).replace(
/[&<>]/g,
t => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;" }[t])
)
}

function broadcastOperation(amount, from_user, to_user, operation){
if(amount==0){ return }

let prefix = "+";
if(amount<0){ prefix = "-" }

let name = isAdmin() ? "admin" : Libs.commonLib.getNameFor(from_user);
let other_name = Libs.commonLib.getNameFor(to_user);
if(operation){ operation+= "\n" }
if(!operation){ operation = "" }
broadcastToChanell(operation + name + " > " + other_name + ": " + prefix + amount + "💎");
// Format a user's display name
function getUserSimpleName(u) {
if (!u) return "Unknown"
if (u.username) return `@${u.username}`
if (u.first_name) return escapeHTML(u.first_name)
if (u.last_name) return escapeHTML(u.last_name)
return "User"
}

function transferPoint(){
res.removeAnyway(1)
anotherRes = Libs.ResourcesLib.anotherUserRes("BBPoint", answer.answer_from_id);
anotherRes.add(1);
// Format current date and time as readable string
function formatTimestamp() {
const now = new Date()
const yyyy = now.getFullYear()
const mm = String(now.getMonth() + 1).padStart(2, "0")
const dd = String(now.getDate()).padStart(2, "0")
const hh = String(now.getHours()).padStart(2, "0")
const min = String(now.getMinutes()).padStart(2, "0")
return `${yyyy}-${mm}-${dd} ${hh}:${min}`
}

function showAlert(text){
Api.answerCallbackQuery({
callback_query_id: req.request_id,
text: text,
show_alert: true // or false - for alert on top
// Send message to info channel for logs or announcements
function broadcastToChannel(text) {
let channel =
AdminPanel.getFieldValue({
panel_name: "Options",
field_name: "InfoChannel"
}) || ""

channel = channel.trim() || "@BBPointBotNew"

Api.sendMessage({
chat_id: channel,
text,
parse_mode: "HTML"
})
}

function havePointOnRequest(req){
let res = Libs.ResourcesLib.userRes("BBPoint");
// Build and broadcast operation details (transfer, punishment, etc.)
function broadcastOperation(amount, from_user, to_user, reason, muteInfo) {
if (!amount || amount === 0) return

if(!res.have(req.amount)){
showAlert("Not enough 💎.\nYou have only: " +
res.value() + "💎");
return
const prefix = amount > 0 ? "+" : ""
const timestamp = formatTimestamp()

const fromName = isAdmin() ? "Admin" : getUserSimpleName(from_user)
const toName = getUserSimpleName(to_user)

let base = `📅 ${timestamp} | ${fromName} > ${toName}: ${prefix}${amount} 💎`

if (muteInfo && amount < 0) {
base += ` (Punishment: ${muteInfo})`
} else if (muteInfo && amount > 0) {
base += ` (Unban: ${muteInfo})`
}
return true
}

function parseRequestParams(){
// we have params like req10-X-points-to-TgID
// return { amount: X, transferred_to_tg_id: Y }
if(params==""){ return }
if (reason && reason.trim() !== "") {
const cleaned = reason.replace(/^-+\s*/, "")
base += `\n📝 Reason: ${escapeHTML(cleaned)}`
}

let arr = params.split("-")
let webhook_url = Bot.getProperty("extUrl_" + arr[0].split("req")[1]);
broadcastToChannel(base)
}

// Display alert popup for callback query
function showAlert(text) {
Api.answerCallbackQuery({
callback_query_id:
typeof req !== "undefined" && req.request_id ? req.request_id : "",
text,
show_alert: true
})
}

// Parse incoming request parameters for webhook data
function parseRequestParams() {
if (!params || params === "") return null
const arr = params.split("-")
const webhook_id = (arr[0] || "").split("req")[1]
const webhook_url = Bot.getProperty("extUrl_" + webhook_id)
return {
webhook_url: webhook_url,
amount: parseInt(arr[1]),
transferred_to_tg_id: arr[4], // telegram id
message_id: arr[5],
request_id: arr[6],
// sometime we have JSON parse error winh first_name, last_name
// make json without thems
user: {
id: user.id,
telegramid: user.telegramid,
username: user.username,
language_code: user.language_code,
created_at: user.created_at
}
webhook_url,
amount: parseInt(arr[1], 10),
transferred_to_tg_id: arr[4],
message_id: arr[5],
request_id: arr[6],
user: {
id: user.id,
telegramid: user.telegramid,
username: user.username,
language_code: user.language_code,
created_at: user.created_at
}
}
}

1 change: 1 addition & 0 deletions commands/Payment Service/_afterNotify.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
answer:
keyboard:
aliases:
group:
CMD*/

let req = parseRequestParams() // { amount: X, transferred_to_tg_id: Y }
Expand Down
12 changes: 0 additions & 12 deletions commands/Payment Service/_cancelRequest.js

This file was deleted.

3 changes: 3 additions & 0 deletions commands/Payment Service/_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ See demo @BBWebhookBot
ANSWER
keyboard:
aliases:
group:
CMD*/

if (chat.chat_type != "private") {return}

let url = message;

let lastIndex = Bot.getProperty("lastExternalUrlIndex", 0);
Expand Down
75 changes: 75 additions & 0 deletions commands/Payment Service/_runTransfer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*CMD
command: /runTransfer
help:
need_reply: false
auto_retry_time:
folder: Payment Service

<<ANSWER

ANSWER

<<KEYBOARD

KEYBOARD
aliases:
group:
CMD*/

// Command: /runTransfer

// Skip if params missing
if (!params) return

// Split first word as action type (accept or cancel)
let arr = params.split(" ")
let action = arr[0]
let data = arr.slice(1).join(" ")

// Handle cancel button press
if (action === "cancel") {
// Notify user and delete message
Api.answerCallbackQuery({
callback_query_id: request.id,
text: "❌ Transfer canceled.",
show_alert: false
})
Api.deleteMessage({ message_id: request.message.message_id })
return
}

// Handle accept button press
if (action === "accept") {
// Parse request details from params
let req = parseRequestParams()
// Append message id and callback id for webhook tracking
params = data + "-" + request.message.message_id + "-" + request.id

// Validate balance or transfer condition
if (!havePointOnRequest(req)) return

// Notify user of acceptance
Api.answerCallbackQuery({
callback_query_id: request.id,
text: "✅ Transfer started...",
show_alert: false
})

// Send webhook notification
HTTP.post({
url: req.webhook_url,
success: "/afterNotify " + params,
error: "/afterNotifyError " + params,
body: req
})
}

/*
Changes made:
- Combined accept and cancel into one unified command (/runTransfer)
- Used params to detect action type
- Added callback query responses for user feedback
- Deleted message on cancel, triggered webhook on accept
- Simplified logic for faster, single-command handling
*/

Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
/*CMD
command: /acceptRequest
help:
need_reply:
need_reply: false
auto_retry_time:
folder: Payment Service
answer:
keyboard:
folder: Removed Commands

<<ANSWER

ANSWER

<<KEYBOARD

KEYBOARD
aliases:
group:
CMD*/

// we have params like req10-X-points-to-TgID
Expand All @@ -24,3 +31,4 @@ HTTP.post( {
body: req
})

// For this ive made the /runTransfer new Command please Check
Loading