Telegram bot for DIY support

Imagine that you have your own channel in the Cart. Let's say you express an unpopular political point of view and, accordingly, catch a personal hate on the part of readers and passing by.





Or, for example, you are selling something through your channel. There are so many clients that one "salesperson" (= you) cannot cope. Or your business support responds to everyone in the public chat that is attached to your channel. But many are embarrassed to ask questions, as they can be seen, so they write in a personal message, which does not scale.





There are many problems, but there is only one solution: to make a Telegram bot that will work as an intermediary between your clients and the support team.





My opinion : this is the best use of telegram bots in the entire history of their existence. In second place is the distribution of classified information via a bot only to paid users.





- Livegrambot. , " Livegrambot", . , , .





, 1 .





TL;DR: : https://github.com/ohld/telegram-support-bot





.

:





  • ( , ),





  • ( , ),





  • ( ).





:





  1. ,





  2. ,





  3. ,





  4. ( reply),





  5. , .





: , .





? , .

, . , , . , Heroku, , .





README.md Heroku, . , Heroku ( 1 ), :





Heroku , , , . :





- App name: Heroku. .





- Choose a region: . .





- HEROKU_APP_NAME



: , App name ( , ).





- TELEGRAM_SUPPORT_CHAT_ID



: , . - .





- TELEGRAM_TOKEN



: , BotFather.





TELEGRAMSUPPORTCHAT_ID





, - . , , " ", chat_id



.





?

. , . , .





Python python-telegram-bot



. GitHub (), .





( )





3 ():





from telegram.ext import Updater
from telegram.ext import CommandHandler, MessageHandler, Filters

updater = Updater(TELEGRAM_TOKEN)
dp = updater.dispatcher

#      "   {username}"
dp.add_handler(CommandHandler('start', start))

#       
dp.add_handler(MessageHandler(Filters.chat_type.private, forward_to_chat))

#       
dp.add_handler(MessageHandler(Filters.chat(TELEGRAM_SUPPORT_CHAT_ID) & Filters.reply, forward_to_user))
      
      



/start . - - , ().





def start(update, context):
    update.message.reply_text(WELCOME_MESSAGE)

    user_info = update.message.from_user.to_dict()

    context.bot.send_message(
        chat_id=TELEGRAM_SUPPORT_CHAT_ID,
        text=f"? Connected {user_info}.",
    )
      
      



, ():





def forward_to_chat(update, context):
    update.message.forward(chat_id=TELEGRAM_SUPPORT_CHAT_ID)
      
      



(reply) , . .forward



, . Telegram Bot API ():





def forward_to_user(update, context):
    user_id = update.message.reply_to_message.forward_from.id
    context.bot.copy_message(
        message_id=update.message.message_id,
        chat_id=user_id,
        from_chat_id=update.message.chat_id
    )
      
      



Heroku





Heroku, Webhook, Pooling. , " ", " ". , (, , - ). , , , .





, Heroku ( ). "" , . , .





, Webhook, , endpoint. : " - ". - , , . , https.





, Heroku https, python-telegram-bot



. URL, , .





webhook- () :





#    
updater.start_webhook(
  listen="0.0.0.0",
  port=PORT,  # HEROKU ,       
  url_path=TELEGRAM_TOKEN  #     ,  
)

#  : "     "
updater.bot.set_webhook(f"https://{HEROKU_APP_NAME}.herokuapp.com/{TELEGRAM_TOKEN}")
updater.idle()
      
      



, HEROKU_APP_NAME



, Heroku App? , , Heroku . , , " App Name " .





?





, , . ?





-, , - . , . -, : CRM, , .






Thanks for watching. Now you know how you can make and deploy a Telegram support bot for free. The complete code of the project (along with the magic button "Deploy this on Heroku") is here . In my Telegram channel, I share my experience in developing large telegram bots, share datasets and product analytics. Come on in.





What other popular Telegram bot use cases would you highlight? Write in the comments.








All Articles