Bots.Business - Help
  • Welcome
  • Getting started
  • Create bot from Google Table
  • App
    • Reset or Update Your Password
  • Commands
    • Answer
    • Aliases
    • Keyboard
    • Groups
    • Wait for answer
    • Auto Retry (AR)
  • Coding: BJS
    • Variables
    • Bot functions
    • Message broadcasting and editing
    • User functions
    • Properties
    • Always running commands
    • Error command: "!"
    • Lists
      • Migration from properties to list
    • Api functions
    • BB Admin functions
    • Admin Panel
    • Send HTTP request
    • Web App
    • Caching
    • Inline Bot
    • BJS Security
    • Good coding practices
    • Top errors
  • Git
    • Import bot from Git repository
    • Export bot to Git repository
    • Repository structure
    • File: bot.json
    • Automatic importing on Git push
  • Iterations. How to reduce theys?
  • Limitations
  • Cloud
  • Reports
  • Deep Linking - pass any params on Bot starting
  • How to link chat account with BB account?
  • BB Inspection
  • Protected bot
  • VS Code
  • How to...
  • Smart Bot
    • Overview
    • Lang File
    • SmartBot
    • SmartTasker
    • Amount Dialog
  • Libs
    • What it is - Libs?
    • Libs development
    • RefferalLib
    • ResourcesLib
    • Random
    • MembershipChecker (MCL)
    • Cooldown Lib
    • CurrencyConverter
    • Lang
    • TopBoardLib
    • QiwiPayments
    • Coinbase (CB)
    • CoinPayments (CP)
    • OxaPay
    • CryptoJS
    • CurrencyQuote
    • GoogleApp
    • GoogleTableSync
    • Guard
    • Webhooks lib
    • DateTimeFormat Lib
  • Store
    • BB Point Bot
    • Welcome bot
    • Help bot
    • SRB Demo Keyboard Tools
Powered by GitBook
On this page
  • Good morning every day
  • Greeting all new member

Was this helpful?

  1. Store

Welcome bot

PreviousBB Point BotNextHelp bot

Last updated 6 years ago

Was this helpful?

This bot greeting all new members in chat and say "Good morning" every day.

Good morning every day

We use for this. Every 50 minutes we check time. If current hour is 6 AM - bot send greeting message to all chat.

Auto retry run periodically.

We have 50 minutes - so we iterate every hour without repeating.

Set 3000 to Auto Retry:

Users can not run this command.

Bot send message to ALL chats. If user run this command at 6 AM - bot send message too!

We need check for auto retry only. Auto Retry do not have chat variable. Execution breaks if chat exist.

// can be runned with Auto Retry only!
if(chat){ return }

Then other code:

let time = new Date()
let hours = time.getHours();
let minutes = time.getMinutes();

curTime = "Time: " + hours + ":" + minutes + " GMT-0";
msg = "";

if(hours==6){
  msg = "Good morning!\n" + curTime;
}

Bot.sendMessageToAllChats(msg);

Greeting all new member

We use Master commad "*" for this. it capture all messages.

Request can have information about new members:

let new_members = request.new_chat_members;

We need build greetings for all users:

if(new_members.length > 0){
   for(var i=0; i<new_members.length; i++){
      msg = msg + comma + getNameFor(new_members[i])
      comma = ", ";
   }
   Bot.sendMessage(msg);
}

User can have username or first name. Or have not:

function getNameFor(member){
   let haveAnyNames = member.username&&member.first_name;
   if(!haveAnyNames){ return ""}

   return member.username ? ("@" + member.username) : member.first_name
}

All code:

let new_members = request.new_chat_members;
let msg = "Hello, ";
let comma = "";

function getNameFor(member){
   let haveAnyNames = member.username&&member.first_name;
   if(!haveAnyNames){ return ""}

   return member.username ? ("@" + member.username) : member.first_name
}

if(new_members.length > 0){
   for(var i=0; i<new_members.length; i++){
      msg = msg + comma + getNameFor(new_members[i])
      comma = ", ";
   }
   Bot.sendMessage(msg);
}

if(request.left_chat_member){
  Bot.sendMessage(
    "Goodbye, " + getNameFor(request.left_chat_member)
  );
}

Auto Retry