{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Telegram Bot"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2\n",
"from TelegramBotNotifications import TelegramBot\n",
"import decouple"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"### TELEGRAM BOT\n",
"# Checking new users\n",
"No new users.\n"
]
}
],
"source": [
"t=TelegramBot(\n",
" #this is the API token, string\n",
" decouple.config(\"TELEGRAM_TOKEN\"),\n",
" channel_mode=True,\n",
" users_path=\"../../../telegram_users.csv\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" username | \n",
" date | \n",
" chat_id | \n",
" message | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" None | \n",
" 2022-03-30 17:19:52+00:00 | \n",
" 5055308345 | \n",
" F72LEZ5UEC | \n",
"
\n",
" \n",
" 1 | \n",
" None | \n",
" 2022-03-30 17:19:53+00:00 | \n",
" 5055308345 | \n",
" C64KMDK6HB | \n",
"
\n",
" \n",
" 2 | \n",
" None | \n",
" 2022-03-30 17:19:55+00:00 | \n",
" 5055308345 | \n",
" RMOAQOA2GE | \n",
"
\n",
" \n",
" 3 | \n",
" None | \n",
" 2022-03-30 17:22:36+00:00 | \n",
" 5055308345 | \n",
" XA8JEZUAJK | \n",
"
\n",
" \n",
" 4 | \n",
" None | \n",
" 2022-03-30 17:22:39+00:00 | \n",
" 5055308345 | \n",
" KR4PK9NYEB | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" username date chat_id message\n",
"0 None 2022-03-30 17:19:52+00:00 5055308345 F72LEZ5UEC\n",
"1 None 2022-03-30 17:19:53+00:00 5055308345 C64KMDK6HB\n",
"2 None 2022-03-30 17:19:55+00:00 5055308345 RMOAQOA2GE\n",
"3 None 2022-03-30 17:22:36+00:00 5055308345 XA8JEZUAJK\n",
"4 None 2022-03-30 17:22:39+00:00 5055308345 KR4PK9NYEB"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t.updates"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" chat_id | \n",
" username | \n",
" date_joined | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 5055308345 | \n",
" admin | \n",
" 2022-02-06 21:55:54+00:00 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" chat_id username date_joined\n",
"0 5055308345 admin 2022-02-06 21:55:54+00:00"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t.users"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"t.send_message_to_user(\"ciao\",\"admin\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"UserNotFoundError\n"
]
}
],
"source": [
"t.send_message_to_user(\"ciao\",\"addmin\")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SendPhotoError\n"
]
}
],
"source": [
"t.send_photo(\"../temp/ADA_20220201-214758.jpeg\",888418315)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'error': 'UserNotFoundError', 'e': KeyError('addmin')},\n",
" {'error': 'SendPhotoError',\n",
" 'e': FileNotFoundError(2, 'No such file or directory')}]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t.error_log"
]
}
],
"metadata": {
"interpreter": {
"hash": "2e02a164808c41417adc12155d25fe4bbfd713e61a4a1963afc9ad34588db99f"
},
"kernelspec": {
"display_name": "Python 3.7.11 64-bit ('crypto': conda)",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.12"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}