Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Internal test bots

Bibo-Joshi edited this pageJan 1, 2023 ·24 revisions

Note: This guide is of no use to the regular user.

Variables:

CI = AppVeyor|Travispy_platform = CPython|PyPypy_version = 2.7|3.4|3.5|3.6|3.7bot_username = ptb_{CI.lower()}_{py_platform.lower()}_{py_version.replace('.', '')}_bot

Script

Here is a script that does all the setup below in a semi automated way using Telethon. Also checkthis version, which was updated for the animated sticker sets and automatically creates a new super group for the bot to be added to (see#1919).⚠️ The script needs to be updated to create a forum test group for each bot and make the bot admin (with right to edit forums!) in that group. TeltehonsToggleForumRequest is helpful for converting groups to forums.

Note: It doesn't create the video sticker set yet, but the test suite creates that on the fly, if necessary.

Setup a new bot

# meanssend a message to @BotFather
% meansclick button in inlinekeyboard

Create the bot

# /newbot
# Python-telegram-bot tests on {CI} using {py_platform} {py_version}(Bot name)
# {bot_username}(Bot username)

The token for the new bot will be shown.

Allow the bot to talk to you

Search for the bot, and press theStart button

Set texts in case a user stumbles upon the bot

# /set_description
# @{bot_username}
# This bot is only for running tests for python-telegram-bot and has no actual functionality.

# /set_abouttext
# @{bot_username}
# This bot is only for running tests for python-telegram-bot and has no actual functionality.

Make sure it can join groups

# /setjoingroups
# @{bot_username}
# Enable

Add it to the developer group

>>> telegram.Bot() - Developers

Add it to the testing channel

>>> telegram.Bot() - Tests

Make sure it can not join groups anymore

# /setjoingroups
# @{bot_username}
# Disable

Turn on inline so we can create a game for the bot

# /set_inline
# @{bot_username}
# This bot is only for running tests.

Create a game for the bot

# /newgame
# OK
# Accept
# @{bot_username}
# Python-telegram-bot test game
# A no-op test game, for python-telegram-bot bot framework testing.
Upload tests/data/game.png
Upload tests/data/game.gif
# test_game

Payment

Now we need to setup payment. This can only be done via the beta /mybots interface.

# /mybots
% @{bot_username}
% Payments
% Stripe(might have a flag in front, depending on your country)
% Connect Stripe Test
Press start in @StripeTestBot
% Authorize
Press "Skip this account form" at the top of your browser
Go back to @StripeTestBot and make sure everything went well
Go back to @BotFather

The payment provider token should be displayed in the last message.

Create a sticker set for the bot

We need to use the bot api to do this.

me_id = YOURUSERIDsticker_set_name = 'test_by_{username}sticker_set_title = 'Test',sticker = 'tests/data/telegram_sticker.png',sticker_emoji = '😄'bot = telegram.Bot(token)with open(sticker, 'rb') as f:    assert bot.create_new_sticker_set(me.id, sticker_set_name, sticker_set_title,                                      f, sticker_emoji)

Create an animated sticker set for the bot

We need to use the bot api to do this.

me_id = YOURUSERIDanimated_sticker_set_name = 'test_by_{username}animated_sticker_set_title = 'Test',animated_sticker = 'tests/data/telegram_animated_sticker.png',sticker_emoji = '😄'bot = telegram.Bot(token)with open(animated_sticker, 'rb') as f:    assert bot.create_new_sticker_set(me.id, animated_sticker_set_name, animated_sticker_set_title,                                      f, sticker_emoji)

Create a video sticker set for the bot

Similar to above

Wiki ofpython-telegram-bot © Copyright 2015-2025 – Licensed byCreative Commons

Must read

  1. Introduction to the API
  2. Tutorial: Your first bot
  3. FAQ
  4. How to ask good questions
  5. How to write an MWE

Concepts & Important Elements

  1. Architecture Overview
  2. Builder Pattern forApplication
  3. Types of Handlers
  4. Working with Files and Media
  5. Exceptions, Warnings and Logging
  6. Concurrency in PTB

Notable Features

  1. Advanced Filters
  2. Storing data
  3. Making your bot persistent
  4. Adding Defaults
  5. Job Queue
  6. Arbitrarycallback_data
  7. Avoiding flood limits
  8. Webhooks
  9. Bot API Forward Compatiblity

Code Resources

  1. Frequently requested design patterns
  2. Code snippets
  3. Performance Optimizations
  4. Telegram Passport
  5. Bots built with PTB
  6. Automated Bot Tests

Examples explained

  1. InlineKeyboard Example

Networking

  1. Working Behind a Proxy
  2. Handling network errors

Other resources

  1. Where to host Telegram Bots
  2. How to host your bot
  3. Local API Server
  4. Type Checking with PTB
  5. Press
  6. Notes on GAE
  7. Related Projects
  8. Emoji

Transition Guides

Administration

Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp