Answer the question
In order to leave comments, you need to log in
How to transfer information from a telegram bot to google tables?
There is a telegram bot that, in response to a text message, forwards it in response. If you send a video file, then the bot sends a file_id in response. There is a script for editing a Google spreadsheet. Using the subprocess module in the google spreadsheet script, it turns out to launch the telegram bot. I need text messages sent to the bot to be entered in one column in Google tables, and file_id (sent videos to the bot) in the other column. Please help make this happen.
Here is the telegram bot code:
import telebot
bot = telebot.TeleBot('токен бота, думаю, вам не нужен)))')
@bot.message_handler(content_types=['text'])
def repeat_all_message(message):
print(message.text)
bot.send_message(message.chat.id,message.text)
@bot.message_handler(content_types=['video'])
def command_handle_video(message):
bot.send_message(message.chat.id, message.video.file_id)
print(message.video.file_id)
if __name__ == '__main__':
bot.polling(none_stop=True)
# Подключаем библиотеки
import httplib2
import apiclient.discovery
from oauth2client.service_account import ServiceAccountCredentials
import subprocess
CREDENTIALS_FILE = 'cybernetic-apex-306610-trtr21fdf.json' # Имя файла с закрытым ключом, вы должны подставить свое
# Читаем ключи из файла
credentials = ServiceAccountCredentials.from_json_keyfile_name(CREDENTIALS_FILE, ['https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/drive'])
httpAuth = credentials.authorize(httplib2.Http()) # Авторизуемся в системе
service = apiclient.discovery.build('sheets', 'v4', http = httpAuth) # Выбираем работу с таблицами и 4 версию API
results = service.spreadsheets().values().batchUpdate(spreadsheetId = '1FX11pgtcvm6OPgmxTEao-25LOW22cbokVJ_pMXZYHvw', body = {
"valueInputOption": "USER_ENTERED", # Данные воспринимаются, как вводимые пользователем (считается значение формул)
"data": [
{"range": "Лист номер один!A2:B10",
"majorDimension": "ROWS", # Сначала заполнять строки, затем столбцы
"values": [
["Text message", "File_id"], # Заполняем первую строку
['result = p.communicate()[0]', 'Id'] # Заполняем вторую строку
]}
]
}).execute()
p=subprocess.Popen(['/usr/bin/python3', '/home/roman/PycharmProjects/uznaemfileID/file_id.py', 'stdout=subprocess.PIPE', 'stderr=subprocess.STDOUT'])
result = p.communicate()[0]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question