-
Notifications
You must be signed in to change notification settings - Fork 0
/
telegram_validate_app.py
568 lines (510 loc) · 33.7 KB
/
telegram_validate_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
import urllib
import telebot
from configs.credentials import telegram_auth_token
from service.service import Service
from repo.repo import Repository
import uuid
from configs.config import dekho_validate_string,validate_selection_string,list_of_tasks,bolo_validate_string,suno_validate_string,likho_target_validate_string,likho_source_validate_string
import shutil
import requests
from PIL import Image
from io import BytesIO
from math import ceil
import os
bot = telebot.TeleBot(telegram_auth_token)
service = Service()
repo = Repository()
username = "Telegram_Bot"
db_response=None
# Handle '/start' and '/help'
@bot.message_handler(commands=['help', 'start'])
def send_welcome(message):
#Store user details
phone_number = str(message.from_user.id)
#Store task_selected and language_selected = None
#If an entry with id as phone_number doesn't exist, create one.
if(service.create_user(phone_number)) == "Already Exists":
repo.update_entry({"$set":{"task_selected":None,"language_selected":None}},phone_number)
bot.reply_to(message,validate_selection_string,parse_mode= 'Markdown')
@bot.message_handler(func=lambda incoming_message: True)
def echo_message(incoming_message):
input = incoming_message.text
responded = False
print("INCOMING MESSAGE : ",incoming_message)
phone_number = str(incoming_message.from_user.id)
#Get user details from db
response = service.get_user_details(phone_number)
print("DB Response",response)
db_response = response
if response is None:
service.create_user(phone_number)
response = service.get_user_details(phone_number)
db_response = response
print("DB Response",response)
#If Task is selected in the current incoming text:
elif response['task_selected'] == None and service.get_task(input) is not None:
task_selected = service.get_task(input)
repo.update_entry({"$set":{"task_selected":task_selected}},phone_number)
if task_selected == "Bolo":
bot.reply_to(incoming_message, bolo_validate_string,parse_mode= 'Markdown')
elif task_selected == "Dekho":
bot.reply_to(incoming_message, dekho_validate_string,parse_mode= 'Markdown')
elif task_selected == "Suno":
bot.reply_to(incoming_message, suno_validate_string,parse_mode= 'Markdown')
elif task_selected == "Likho":
bot.reply_to(incoming_message, likho_source_validate_string,parse_mode= 'Markdown')
responded = True
#If word is MORE / LANG / CHANGE
#Input is LANG:
elif responded == False and input.lower() == "lang":
repo.update_entry({"$set":{"language_selected":None}},phone_number)
if response["task_selected"] == None:
bot.reply_to(incoming_message, "Please select a task in order to change the language\n"+validate_selection_string,parse_mode= 'Markdown')
responded = True
elif response["task_selected"] == "Bolo":
service.remove_submitted_false(phone_number)
bot.reply_to(incoming_message, bolo_validate_string,parse_mode= 'Markdown')
elif response["task_selected"] == "Dekho":
service.remove_submitted_false(phone_number)
bot.reply_to(incoming_message, dekho_validate_string,parse_mode= 'Markdown')
elif response["task_selected"] == "Suno":
service.remove_submitted_false(phone_number)
bot.reply_to(incoming_message, suno_validate_string,parse_mode= 'Markdown')
elif response["task_selected"] == "Likho":
service.remove_submitted_false(phone_number)
bot.reply_to(incoming_message, likho_source_validate_string,parse_mode= 'Markdown')
responded = True
#If input is CHANGE
elif responded == False and input.lower() == "change":
if response["task_selected"] == "likho":
repo.update_entry({"$set":{"likho_source_language_selected":None,"likho_target_language_selected":None}},phone_number)
repo.update_entry({"$set":{"task_selected":None,"language_selected":None}},phone_number)
bot.reply_to(incoming_message,validate_selection_string,parse_mode= 'Markdown')
responded = True
#If language is selected by user as a number Or if MORE is entered as input
elif responded == False and response['task_selected'] != None and service.get_number_of_input(input) is not None:
if response['task_selected'] == "Bolo":
if service.get_number_of_input(input) == 0:
lang_selected = response["language_selected"]
else:
lang_selected = service.get_bolo_language_from_code(input)
function_response = service.fetch_audio(lang_selected,username)
if function_response is not None:
phone_number = str(incoming_message.from_user.id)
#(dataset_row_id, contribution, contribution_id, content_url)
dataset_row_id = function_response[0] #Original Image ID
contribution = function_response[1] #Text
contribution_id = function_response[2] #Text ID
content_url = function_response[3] #URL of Image
#phone_number = phone_number.replace("whatsapp:+","")
response = service.get_search_entry(phone_number,lang_selected,dataset_row_id,contribution,contribution_id,content_url,"bolo_validate",input,delete_submitted=True,updateEntry=True)
repo.update_entry({ "$set" : {"language_selected":lang_selected}},phone_number)
if response is None:
entry = {
"_id":phone_number,
"content":[
{
"submitted": False,
"dataset_row_id": dataset_row_id,
"contribution": contribution,
"contribution_id": contribution_id,
"content_url": content_url,
"language_code": lang_selected,
"taskOperation": 'validate'
}
]
}
repo.create_entry(entry)
try:
f = open("Aud"+phone_number+".wav",'wb')
content_url = content_url.replace(" ","%20")
print("CONTENT URL :",content_url)
f.write(urllib.request.urlopen(content_url).read())
f.close()
audio = open("Aud"+phone_number+".wav", 'rb')
os.remove("Aud"+phone_number+".wav")
bot.send_audio(incoming_message.chat.id, audio, reply_to_message_id=incoming_message.message_id)
bot.reply_to(incoming_message, "Transcript of the audio: "+str(contribution)+"""\n\nPlease respond with "*Y*" if the the audio matches the text or "*N*" if it does not match the text.\n\nPlease type "*LANG*" to view the list of languages and select once again.\n Please type "*CHANGE*" to choose the task again""",parse_mode= 'Markdown')
responded = True
except Exception as e:
print(e)
else:
bot.reply_to(incoming_message, """Unable to fetch the content. Please try again shortly.""",parse_mode= 'Markdown')
responded = True
elif response['task_selected'] == "Dekho":
if service.get_number_of_input(input) == 0:
lang_selected = response["language_selected"]
else:
lang_selected = service.get_dekho_language_from_code(input)
function_response = service.fetch_ocr(lang_selected,username)
if function_response is not None:
phone_number = str(incoming_message.from_user.id)
#(dataset_row_id, contribution, contribution_id, content_url)
dataset_row_id = function_response[0] #Original Image ID
contribution = function_response[1] #Text
contribution_id = function_response[2] #Text ID
content_url = function_response[3] #URL of Image
#phone_number = phone_number.replace("whatsapp:+","")
response = service.get_search_entry(phone_number,lang_selected,dataset_row_id,contribution,contribution_id,content_url,"dekho_validate",input,delete_submitted=True,updateEntry=True)
repo.update_entry({ "$set" : {"language_selected":lang_selected}},phone_number)
if response is None:
entry = {
"_id":phone_number,
"content":[
{
"submitted": False,
"dataset_row_id": dataset_row_id,
"contribution": contribution,
"contribution_id": contribution_id,
"content_url": content_url,
"language_code": lang_selected,
"taskOperation": 'validate'
}
]
}
repo.create_entry(entry)
try:
#Figure out
basewidth = 1000
content_url = content_url.replace(" ","%20")
response = requests.get(content_url)
img = Image.open(BytesIO(response.content))
width,height = img.size
wpercent = (basewidth/float(img.size[0]))
hsize = int((float(img.size[1])*float(wpercent)))
img = img.resize((basewidth,hsize), Image.Resampling.LANCZOS)
width,height = img.size
newH = ceil(width/20)
padded = Image.new('RGB', (width,newH), 'black')
padded.paste(img, (0,int((newH-height)/2)))
padded.save("Img"+phone_number+".jpg")
bot.send_photo(incoming_message.chat.id, photo=open("Img"+phone_number+".jpg", 'rb'))
os.remove("Img"+phone_number+".jpg")
del response
bot.reply_to(incoming_message, contribution+"\n\n"+"""Please respond with "*Y*" if the the image matches the text or "*N*" if it does not match the text.\n\nPlease type "*LANG*" to view the list of languages and select once again.\n Please type "*CHANGE*" to choose the task again""",parse_mode= 'Markdown')
responded = True
except Exception as e:
print(e)
else:
bot.reply_to(incoming_message, """Unable to fetch the content. Please try again shortly.""",parse_mode= 'Markdown')
responded = True
elif response['task_selected'] == "Suno":
if service.get_number_of_input(input) == 0:
lang_selected = response["language_selected"]
else:
lang_selected = service.get_bolo_language_from_code(input)
function_response = service.fetch_suno(lang_selected,username)
if function_response is not None:
phone_number = str(incoming_message.from_user.id)
#(dataset_row_id, contribution, contribution_id, content_url)
dataset_row_id = function_response[0] #Original Audio ID
contribution = function_response[1] #Text
contribution_id = function_response[2] #Text ID
content_url = function_response[3] #URL of Audio
#phone_number = phone_number.replace("whatsapp:+","")
response = service.get_search_entry(phone_number,lang_selected,dataset_row_id,contribution,contribution_id,content_url,"suno_validate",input,delete_submitted=True,updateEntry=True)
repo.update_entry({ "$set" : {"language_selected":lang_selected}},phone_number)
if response is None:
entry = {
"_id":phone_number,
"content":[
{
"submitted": False,
"dataset_row_id": dataset_row_id,
"contribution": contribution,
"contribution_id": contribution_id,
"content_url": content_url,
"language_code": lang_selected,
"taskOperation": 'validate'
}
]
}
repo.create_entry(entry)
try:
f = open("Aud"+phone_number+".wav",'wb')
content_url = content_url.replace(" ","%20")
f.write(urllib.request.urlopen(content_url).read())
f.close()
audio = open("Aud"+phone_number+".wav", 'rb')
os.remove("Aud"+phone_number+".wav")
bot.send_audio(incoming_message.chat.id, audio, reply_to_message_id=incoming_message.message_id)
bot.reply_to(incoming_message, "Transcript of the audio: "+str(contribution)+"""\n\nPlease respond with "*Y*" if the the audio matches the text or "*N*" if it does not match the text.\n\nPlease type "*LANG*" to view the list of languages and select once again.\n Please type "*CHANGE*" to choose the task again""",parse_mode= 'Markdown')
responded = True
except Exception as e:
print(e)
else:
bot.reply_to(incoming_message, """Unable to fetch the content. Please try again shortly.""",parse_mode= 'Markdown')
responded = True
elif response['task_selected'] == "Likho":
source_language_selected = None
target_lang_selected = None
textProvision = False
if service.get_number_of_input(input) == 0 and len(response["language_selected"].split("_")) == 2:
textProvision = True
source_language_selected = response["language_selected"].split("_")[0]
target_language_selected = response["language_selected"].split("_")[1]
else:
#select source language
if response['language_selected'] == None:
lang_selected = service.get_dekho_language_from_code(input)
repo.update_entry({ "$set" : {"language_selected":lang_selected}},phone_number)
bot.reply_to(incoming_message,likho_target_validate_string+"\n\nThe source language selected is "+lang_selected,parse_mode= 'Markdown')
responded = True
elif len(response["language_selected"].split("_")) == 1:
source_language_selected = response["language_selected"]
target_language_selected = service.get_dekho_language_from_code(input)
textProvision = True
#Select target language
if target_language_selected == source_language_selected:
bot.reply_to(incoming_message,"\n\nThe source language selected and target language selected are the same. Please retry. Current source language selected is: *"+languages[0]+"* and target language selected is *"+lang_selected+"*",parse_mode= 'Markdown')
bot.reply_to(incoming_message,likho_target_validate_string,parse_mode= 'Markdown')
responded = True
#repo.update_entry({ "$set" : {"language_selected":lang_selected}},phone_number)
#Logic to provide text back to user:
if textProvision == True:
update_response = repo.update_entry({ "$set" : {"language_selected":source_language_selected+"_"+target_language_selected}},phone_number)
languages = response["language_selected"].split("_")
function_response = service.fetch_sentence_likho(source_language_selected,target_language_selected,username)
if function_response is not None:
phone_number = str(incoming_message.from_user.id)
#(dataset_row_id, contribution, contribution_id, content_url)
dataset_row_id = function_response[0] #Original Audio ID
contribution = function_response[1] #Text
contribution_id = function_response[2] #Text ID
sentence = function_response[3] #URL of Audio
#phone_number = phone_number.replace("whatsapp:+","")
search_function_response = service.get_search_entry(phone_number,source_language_selected+"_"+target_language_selected,dataset_row_id,contribution,contribution_id,sentence,"likho_validate",input,delete_submitted=True,updateEntry=True)
if search_function_response is None:
entry = {
"_id":phone_number,
"content":[
{
"submitted": False,
"dataset_row_id": dataset_row_id,
"contribution": contribution,
"contribution_id": contribution_id,
"content_url": content_url,
"language_code": lang_selected,
"taskOperation": 'validate'
}
]
}
repo.create_entry(entry)
bot.reply_to(incoming_message, "Text in language: *"+
source_language_selected+
"* is\n\n*"+sentence+
"*\n\nand text in language *"+
target_language_selected+
"* is\n\n*"+str(contribution)+
"""*\n\nPlease respond with "*Y*" if the the audio matches the text or "*N*" if it does not match the text.\n\nPlease type "*LANG*" to view the list of languages and select once again.\nPlease type "*CHANGE*" to choose the task again""",parse_mode= 'Markdown')
responded = True
else:
bot.reply_to(incoming_message, """Unable to fetch the content. Please try again shortly.""",parse_mode= 'Markdown')
responded = True
#If Response is y or n (For validate / skip)
elif responded == False and response['task_selected'] != None and response['language_selected'] != None and input.lower() == "y" or input.lower() == "n":
if response['task_selected'] == "Bolo":
submitted = False
function_response1 = function_response2 = None
phone_number = str(incoming_message.from_user.id)
response = service.get_search_entry(phone_number,response['language_selected'])
print("DB Response from get search entry",response)
if response is not None and "content" in response[0].keys():
for each_entry in response[0]['content']:
if each_entry['submitted'] == False:
if(input.lower()=="y"):
function_response1 = service.make_submit_true(phone_number,"accept")
function_response2 = service.bolo_validate_verify(username,each_entry['language_code'],each_entry['dataset_row_id'],each_entry['contribution_id'])
else:
function_response1 = service.make_submit_true(phone_number,"skip")
function_response2 = service.bolo_validate_skip(username,each_entry['language_code'],each_entry['dataset_row_id'],each_entry['contribution_id'])
if function_response1 is not None and function_response2 is not None:
submitted = True
else:
bot.reply_to(incoming_message, "Unable to submit the response at this moment. Please try again later",parse_mode= 'Markdown')
responded = True
break
if response == None or submitted == False:
if responded == False:
bot.reply_to(incoming_message, "Unable to submit the response at this moment. Please try again later",parse_mode= 'Markdown')
responded = True
if responded == False:
responded = True
bot.reply_to(incoming_message, """*Success!* Thanks for your contribution to Bhashadhaan.\nTo continue contributing in the same language, type "*MORE*".\nTo change the language, type "*LANG*".\nTo change the task, type "*CHANGE*".\nFor more info, visit: https://bhashini.gov.in/bhashadaan""",parse_mode= 'Markdown')
elif response['task_selected'] == "Dekho":
submitted = False
function_response1 = function_response2 = None
phone_number = str(incoming_message.from_user.id)
response = service.get_search_entry(phone_number,response['language_selected'])
if response is not None and "content" in response[0].keys():
for each_entry in response[0]['content']:
if each_entry['submitted'] == False:
if(input.lower()=="y"):
function_response1 = service.make_submit_true(phone_number,"accept")
function_response2 = service.verify_sentence(username,each_entry['language_code'],each_entry['dataset_row_id'],each_entry['contribution_id'])
else:
function_response1 = service.make_submit_true(phone_number,"skip")
function_response2 = service.skip_sentence(username,each_entry['language_code'],each_entry['dataset_row_id'],each_entry['contribution_id'])
if function_response1 is not None and function_response2 is not None:
submitted = True
else:
bot.reply_to(incoming_message, "Unable to submit the response at this moment. Please try again later",parse_mode= 'Markdown')
responded = True
break
if response == None or submitted == False:
if responded == False:
bot.reply_to(incoming_message, "Unable to submit the response at this moment. Please try again later",parse_mode= 'Markdown')
responded = True
if responded == False:
responded = True
bot.reply_to(incoming_message, """*Success!* Thanks for your contribution to Bhashadhaan.\nTo continue contributing in the same language, type "*MORE*".\nTo change the language, type "*LANG*".\nTo change the task, type "*CHANGE*".\nFor more info, visit: https://bhashini.gov.in/bhashadaan""",parse_mode= 'Markdown')
if response['task_selected'] == "Suno":
submitted = False
function_response1 = function_response2 = None
phone_number = str(incoming_message.from_user.id)
response = service.get_search_entry(phone_number,response['language_selected'])
print("DB Response from get search entry",response)
if response is not None and "content" in response[0].keys():
for each_entry in response[0]['content']:
if each_entry['submitted'] == False:
if(input.lower()=="y"):
function_response1 = service.make_submit_true(phone_number,"accept")
function_response2 = service.suno_validate_verify(username,each_entry['language_code'],each_entry['dataset_row_id'],each_entry['contribution_id'])
else:
function_response1 = service.make_submit_true(phone_number,"skip")
function_response2 = service.suno_validate_skip(username,each_entry['language_code'],each_entry['dataset_row_id'],each_entry['contribution_id'])
if function_response1 is not None and function_response2 is not None:
submitted = True
else:
bot.reply_to(incoming_message, "Unable to submit the response at this moment. Please try again later",parse_mode= 'Markdown')
responded = True
break
if response == None or submitted == False:
if responded == False:
bot.reply_to(incoming_message, "Unable to submit the response at this moment. Please try again later",parse_mode= 'Markdown')
responded = True
if responded == False:
responded = True
bot.reply_to(incoming_message, """*Success!* Thanks for your contribution to Bhashadhaan.\nTo continue contributing in the same language, type "*MORE*".\nTo change the language, type "*LANG*".\nTo change the task, type "*CHANGE*".\nFor more info, visit: https://bhashini.gov.in/bhashadaan""",parse_mode= 'Markdown')
if response['task_selected'] == "Likho":
submitted = False
function_response1 = function_response2 = None
phone_number = str(incoming_message.from_user.id)
source_lang = response["language_selected"].split("_")[0]
target_lang = response["language_selected"].split("_")[1]
response = service.get_search_entry(phone_number,response['language_selected'])
print("DB Response from get search entry",response)
if response is not None and "content" in response[0].keys():
for each_entry in response[0]['content']:
if each_entry['submitted'] == False:
if(input.lower()=="y"):
function_response1 = service.make_submit_true(phone_number,"accept")
function_response2 = service.verify_sentence_likho(username,source_lang,target_lang,each_entry['dataset_row_id'],each_entry['contribution_id'])
else:
function_response1 = service.make_submit_true(phone_number,"skip")
function_response2 = service.skip_sentence_likho(username,source_lang,target_lang,each_entry['dataset_row_id'],each_entry['contribution_id'])
if function_response1 is not None and function_response2 is not None:
submitted = True
else:
bot.reply_to(incoming_message, "Unable to submit the response at this moment. Please try again later",parse_mode= 'Markdown')
responded = True
break
if response == None or submitted == False:
if responded == False:
bot.reply_to(incoming_message, "Unable to submit the response at this moment. Please try again later",parse_mode= 'Markdown')
responded = True
if responded == False:
responded = True
bot.reply_to(incoming_message, """*Success!* Thanks for your contribution to Bhashadhaan.\nTo continue contributing in the same language, type "*MORE*".\nTo change the language, type "*LANG*".\nTo change the task, type "*CHANGE*".\nFor more info, visit: https://bhashini.gov.in/bhashadaan""",parse_mode= 'Markdown')
# new_file.write(downloaded_file)
# print("FILE_PATH:",file_info.file_path)
# response = service.get_search_entry(phone_number)
# if response is not None and "content" in response[0].keys():
# for each_entry in response[0]['content']:
# if each_entry['submitted'] == False:
# function_response = service.make_submit_true(phone_number,oggfname)
# if function_response is not None:
# username = "T_"+phone_number
# message = service.submit_audio(oggfname,each_entry['language_code'],each_entry['dataset_row_id'],username,"file")
# if message is not None:
# submitted = True
# else:
# bot.reply_to(incoming_message, "Unable to submit the audio at this moment. Please try again later")
# responded = True
# break
# else:
# bot.reply_to(incoming_message, "Unable to perform the operation. Kindly try again later")
# responded = True
# if response == None or submitted == False:
# if responded == False:
# bot.reply_to(incoming_message, "Please select a language to obtain text and then respond with the audio")
# responded = True
# if responded == False:
# bot.reply_to(incoming_message, "Success!!! Thanks for contrubution your audio to Bhashadhaan. To continue contributing, choose a language again. For more details, visit: https://bhashini.gov.in/bhashadaan")
# pass
if responded == False:
if db_response['task_selected']!=None and db_response['language_selected']!=None:
response = f"Dear User, your current selected task is {db_response['task_selected']} and language selected is {db_response['language_selected']}\n\nTo continue contributing in the same language, type MORE.\n\nTo change the language, type LANG.\n\nTo change the task, type CHANGE."
bot.reply_to(incoming_message, response)
elif db_response['language_selected'] == None and db_response['task_selected']!=None:
if db_response["task_selected"] == "Bolo":
bot.reply_to(incoming_message, bolo_validate_string,parse_mode='Markdown')
elif db_response["task_selected"] == "Dekho":
bot.reply_to(incoming_message, dekho_validate_string,parse_mode='Markdown')
else:
bot.reply_to(incoming_message,validate_selection_string,parse_mode='Markdown')
# @bot.message_handler(content_types=['voice'])
# def voice_processing(incoming_message):
# responded = False
# submitted = False
# phone_number = str(incoming_message.from_user.id)
# file_info = bot.get_file(incoming_message.voice.file_id)
# downloaded_file = bot.download_file(file_info.file_path)
# fid = str(uuid.uuid4())
# oggfname = fid+".ogg"
# with open(oggfname, 'wb') as new_file:
# new_file.write(downloaded_file)
# print("FILE_PATH:",file_info.file_path)
# response = service.get_search_entry(phone_number)
# if response is not None and "content" in response[0].keys():
# for each_entry in response[0]['content']:
# if each_entry['submitted'] == False:
# function_response = service.make_submit_true(phone_number,oggfname)
# if function_response is not None:
# username = "T_"+phone_number
# message = service.submit_audio(oggfname,each_entry['language_code'],each_entry['dataset_row_id'],username,"file")
# if message is not None:
# submitted = True
# else:
# bot.reply_to(incoming_message, "Unable to submit the audio at this moment. Please try again later")
# responded = True
# break
# else:
# bot.reply_to(incoming_message, "Unable to perform the operation. Kindly try again later")
# responded = True
# if response == None or submitted == False:
# if responded == False:
# bot.reply_to(incoming_message, "Please select a language to obtain text and then respond with the audio")
# responded = True
# if responded == False:
# bot.reply_to(incoming_message, "Success!!! Thanks for contrubution your audio to Bhashadhaan. To continue contributing, choose a language again. For more details, visit: https://bhashini.gov.in/bhashadaan")
# # Handle all other messages with content_type 'text' (content_types defaults to ['text'])
# @bot.message_handler(func=lambda message: True)
# def echo_message(message):
# print(message)
# bot.reply_to(message, message.text)
# @bot.message_handler(content_types=['photo'])
# def photo(message):
# print(message)
# fileID = message.photo[-1].file_id
# file_info = bot.get_file(fileID)
# downloaded_file = bot.download_file(file_info.file_path)
# with open("image.jpg", 'wb') as new_file:
# new_file.write(downloaded_file)
# @bot.message_handler(content_types=['voice'])
# def voice_processing(message):
# file_info = bot.get_file(message.voice.file_id)
# downloaded_file = bot.download_file(file_info.file_path)
# with open('new_file.ogg', 'wb') as new_file:
# new_file.write(downloaded_file)
bot.infinity_polling()