Ejemplo n.º 1
0
 def try_process_number(self,  first_name, chat_id, number):
     db = DbHelper()
     rows = db.execute_select("SELECT * FROM {}.{} WHERE user_name = '{}' AND chat_id='{}'"
                              .format(
                                  self.config.get("postgresql","schema"),
                                  self.config.get("postgresql","users_table"),
                                  first_name,
                                  chat_id))
     if len(rows)!=0 and rows[0][4]==1:
         twillio_message = str(random.randint(0,9)) + str(random.randint(0,9)) + str(random.randint(0,9)) + str(random.randint(0,9))
         if (number[0]=="7"):
             number="+" + number
         db.execute_sql("UPDATE {}.{} SET phone_number='{}', sms_code='{}', status={}  WHERE user_name='{}' and chat_id='{}'"
                        .format(
                            self.config.get("postgresql","schema"),
                            self.config.get("postgresql","users_table"),
                            number,
                            twillio_message,
                            2,
                            first_name,
                            chat_id))
         LogDBHandler.log(Actions.phone_number_recieved, self.config.get("botsettings","messenger_name"), number, "", "success", "user", chat_id)
         Twilio.send_sms(twillio_message, number)
         LogDBHandler.log(Actions.code_sended,self.config.get("botsettings","messenger_name"),number,"","success","bot",chat_id)
         self.send_message(self.config.get("messages","confirmation_message"), chat_id)
Ejemplo n.º 2
0
 def try_process_code(self,  first_name, chat_id, number):
     db = DbHelper()
     rows = db.execute_select("SELECT * FROM {}.{} WHERE user_name = '{}' AND chat_id='{}'"
                              .format(
                                  self.config.get("postgresql","schema"),
                                  self.config.get("postgresql","users_table"),
                                  first_name,
                                  chat_id))
     if len(rows)!=0 and rows[0][4]==2:
         try:
             if int(number)==rows[0][5]:
                 db.execute_sql("UPDATE {}.{} SET status={}  WHERE user_name='{}' and chat_id='{}'"
                                .format(
                                    self.config.get("postgresql","schema"),
                                    self.config.get("postgresql","users_table"),
                                    3,
                                    first_name,
                                    chat_id))
                 self.send_message(configuration.get_database_param("subscribed_message"), chat_id)
                 LogDBHandler.log(Actions.registred,configuration.get_database_param("messanger_name"),self.get_phone_number(chat_id),str(number),"success","bot",chat_id)
                 return True
             else:
                 self.send_message(configuration.get_database_param("wrong_code_message"), chat_id)
                 LogDBHandler.log(Actions.registred,configuration.get_database_param("messanger_name"),self.get_phone_number(chat_id),str(number),"failed","bot",chat_id,"wrong confirmation code")
                 return True
         except Exception as e: 
             self.send_message(configuration.get_database_param("wrong_code_message"), chat_id)
             LogDBHandler.log(Actions.registred,configuration.get_database_param("messanger_name"),self.get_phone_number(chat_id),str(number),"failed","bot",chat_id,"wrong confirmation code")
             return True
     else:
         return False
Ejemplo n.º 3
0
 def unsubscribe(self, first_name, chat_id):
     db = DbHelper()
     db.execute_sql("DELETE FROM {}.{} WHERE user_name = '{}' AND phone_number = '{}'"
                    .format(
                        self.config.get("postgresql","schema"),
                        self.config.get("postgresql","users_table"),
                        first_name,
                        chat_id))
     LogDBHandler.log(Actions.unsubscribed, self.config.get("botsettings","messenger_name"), self.get_phone_number(chat_id), "", "success", "user", chat_id)
     self.send_message(self.config.get("messages","unsubscribed_message"), chat_id)
Ejemplo n.º 4
0
 def unsubscribe(self, first_name, chat_id):
     phone_number = self.get_phone_number(chat_id)
     try:
         
         db = DbHelper()
         db.execute_sql("DELETE FROM {}.{} WHERE user_name = '{}' AND phone_number = '{}'"
                        .format(
                            self.config.get("postgresql","schema"),
                            self.config.get("postgresql","users_table"),
                            first_name,
                            phone_number))
         LogDBHandler.log(Actions.unsubscribed, configuration.get_database_param("messanger_name"), phone_number, "", "success", "bot", chat_id)
         self.send_message(configuration.get_database_param("unsubscribed_message"), chat_id)
     except Exception as e:
         LogDBHandler.log(Actions.unsubscribed, configuration.get_database_param("messanger_name"), phone_number, str(e).replace("/","//").replace("'","\""), "failed", "bot", chat_id)
Ejemplo n.º 5
0
 def log(action,
         messenger,
         phone_number,
         message,
         result,
         direction,
         user_id=0,
         additional_info='',
         sended_json="{}",
         recieved_json="{}"):
     db = DbHelper()
     sql = "INSERT INTO notificator.logs (action_, messenger, phone_number, message, date_time, sended_json, recieved_json, result, direction, user_id, additional_info) values ('{}','{}','{}','{}', to_timestamp('{}', 'YY/mm/DD HH24:MI:SS'), '{}', '{}', '{}', '{}', {}, '{}')".format(
         action, messenger, phone_number, message,
         datetime.now().strftime("%Y/%m/%d %H:%M:%S"), sended_json,
         recieved_json, result, direction, user_id, additional_info)
     db.execute_sql(sql)
Ejemplo n.º 6
0
 def subscribe(self, first_name, chat_id):
     db = DbHelper()
     rows = db.execute_select("SELECT * FROM {}.{} WHERE user_name = '{}' AND chat_id = '{}'"
                              .format(
                                  self.config.get("postgresql","schema"),
                                  self.config.get("postgresql","users_table"),
                                  first_name,
                                  chat_id))
     if len(rows)==0:
         db.execute_sql("INSERT INTO {}.{} (user_name, chat_id, status) VALUES ('{}', '{}', {})"
                        .format(
                            self.config.get("postgresql","schema"),
                            self.config.get("postgresql","users_table"),
                            first_name,
                            chat_id,
                            1))
         #keyboard = self.build_keyboard(telegram.KeyboardButton(text="Поделиться номером телефона", request_contact=True))
         LogDBHandler.log(Actions.registred, self.config.get("botsettings","messenger_name"), self.get_phone_number(chat_id), "", "success", "user", chat_id)
         self.send_message(self.config.get("messages","share_number_message"), chat_id, self.build_keyboard(self.config.get("messages","button_caption")))
     else:
         self.send_message(self.config.get("messages","already_subscribed_message"), chat_id)
Ejemplo n.º 7
0
 def subscribe(self, first_name, chat_id):
     db = DbHelper()
     rows = db.execute_select("SELECT * FROM {}.{} WHERE user_name = '{}' AND chat_id = '{}'"
                              .format(
                                  self.config.get("postgresql","schema"),
                                  self.config.get("postgresql","users_table"),
                                  first_name,
                                  chat_id))
     if len(rows)==0:
         db.execute_sql("INSERT INTO {}.{} (user_name, chat_id, status) VALUES ('{}', '{}', {})"
                        .format(
                            self.config.get("postgresql","schema"),
                            self.config.get("postgresql","users_table"),
                            first_name,
                            chat_id,
                            1))
         #keyboard = self.build_keyboard(telegram.KeyboardButton(text="Поделиться номером телефона", request_contact=True))
        
         self.send_message(configuration.get_database_param("share_number_message"), chat_id, self.build_keyboard(configuration.get_database_param("button_caption")))
     else:
         self.send_message(configuration.get_database_param("already_subscribed_message"), chat_id)
Ejemplo n.º 8
0
 def try_process_code(self,  first_name, chat_id, number):
     db = DbHelper()
     rows = db.execute_select("SELECT * FROM {}.{} WHERE user_name = '{}' AND chat_id='{}'"
                              .format(
                                  self.config.get("postgresql","schema"),
                                  self.config.get("postgresql","users_table"),
                                  first_name,
                                  chat_id))
     if len(rows)!=0 and rows[0][4]==2:
         if int(number)==rows[0][5]:
             db.execute_sql("UPDATE {}.{} SET status={}  WHERE user_name='{}' and chat_id='{}'"
                            .format(
                                self.config.get("postgresql","schema"),
                                self.config.get("postgresql","users_table"),
                                3,
                                first_name,
                                chat_id))
             self.send_message(self.config.get("messages","subscribed_message"), chat_id)
             LogDBHandler.log(Actions.registred,self.config.get("botsettings","messenger_name"),number,"","success","bot",chat_id)
         else:
             LogDBHandler.log(Actions.registred,self.config.get("botsettings","messenger_name"),number,"","failed","bot",chat_id,"wrong confirmation code")
             self.send_message(self.config.get("messages","wrong_code_message"), chat_id)