forked from eternnoir/pyTelegramBotAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8f147f
commit 2f32236
Showing
6 changed files
with
278 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/python | ||
|
||
# This is a simple echo bot using the decorator mechanism. | ||
# It echoes any incoming text messages. | ||
# Example on built-in function to receive and process webhooks. | ||
|
||
from telebot.async_telebot import AsyncTeleBot | ||
import asyncio | ||
bot = AsyncTeleBot('TOKEN') | ||
|
||
|
||
WEBHOOK_SSL_CERT = './webhook_cert.pem' # Path to the ssl certificate | ||
WEBHOOK_SSL_PRIV = './webhook_pkey.pem' # Path to the ssl private key | ||
DOMAIN = '123.12.33.22' # either domain, or ip address of vps | ||
|
||
# Quick'n'dirty SSL certificate generation: | ||
# | ||
# openssl genrsa -out webhook_pkey.pem 2048 | ||
# openssl req -new -x509 -days 3650 -key webhook_pkey.pem -out webhook_cert.pem | ||
# | ||
# When asked for "Common Name (e.g. server FQDN or YOUR name)" you should reply | ||
# with the same value in you put in WEBHOOK_HOST | ||
|
||
|
||
# Handle '/start' and '/help' | ||
@bot.message_handler(commands=['help', 'start']) | ||
async def send_welcome(message): | ||
await bot.reply_to(message, """\ | ||
Hi there, I am EchoBot. | ||
I am here to echo your kind words back to you. Just say anything nice and I'll say the exact same thing to you!\ | ||
""") | ||
|
||
|
||
# Handle all other messages with content_type 'text' (content_types defaults to ['text']) | ||
@bot.message_handler(func=lambda message: True) | ||
async def echo_message(message): | ||
await bot.reply_to(message, message.text) | ||
|
||
|
||
# it uses fastapi + uvicorn | ||
asyncio.run(bot.run_webhooks( | ||
listen=DOMAIN, | ||
certificate=WEBHOOK_SSL_CERT, | ||
certificate_key=WEBHOOK_SSL_PRIV | ||
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/python | ||
|
||
# This is a simple echo bot using the decorator mechanism. | ||
# It echoes any incoming text messages. | ||
# Example on built-in function to receive and process webhooks. | ||
|
||
import telebot | ||
|
||
API_TOKEN = 'TOKEN' | ||
|
||
bot = telebot.TeleBot(API_TOKEN) | ||
|
||
WEBHOOK_SSL_CERT = './webhook_cert.pem' # Path to the ssl certificate | ||
WEBHOOK_SSL_PRIV = './webhook_pkey.pem' # Path to the ssl private key | ||
DOMAIN = '123.12.33.22' # either domain, or ip address of vps | ||
|
||
# Quick'n'dirty SSL certificate generation: | ||
# | ||
# openssl genrsa -out webhook_pkey.pem 2048 | ||
# openssl req -new -x509 -days 3650 -key webhook_pkey.pem -out webhook_cert.pem | ||
# | ||
# When asked for "Common Name (e.g. server FQDN or YOUR name)" you should reply | ||
# with the same value in you put in WEBHOOK_HOST | ||
|
||
|
||
# Handle '/start' and '/help' | ||
@bot.message_handler(commands=['help', 'start']) | ||
def send_welcome(message): | ||
bot.reply_to(message, """\ | ||
Hi there, I am EchoBot. | ||
I am here to echo your kind words back to you. Just say anything nice and I'll say the exact same thing to you!\ | ||
""") | ||
|
||
|
||
# Handle all other messages with content_type 'text' (content_types defaults to ['text']) | ||
@bot.message_handler(func=lambda message: True) | ||
def echo_message(message): | ||
bot.reply_to(message, message.text) | ||
|
||
|
||
bot.run_webhooks( | ||
listen=DOMAIN, | ||
certificate=WEBHOOK_SSL_CERT, | ||
certificate_key=WEBHOOK_SSL_PRIV | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
from .webhooks import SyncWebhookListener | ||
from .webhooks import SyncWebhookListener, AsyncWebhookListener | ||
|
||
|
||
|
||
__all__ = [ | ||
'SyncWebhookListener' | ||
] | ||
'SyncWebhookListener', | ||
'AsyncWebhookListener' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters