class Update: """ update_id: The update's unique identifier. Update identifiers start from a certain positive number and increase sequentially message: New incoming message of any kind - text, photo, sticker, etc. """ def __init__(self, update_message): """ :param update_message: Update received in JSON format :type update_message: Dict """ if 'document' in update_message['message'] \ or 'sticker' in update_message['message'] or 'audio' in update_message['message']: self.update_id = update_message['update_id'] self.message = Message( message_id=update_message['message']['message_id'], date=update_message['message']['date'], chat=update_message['message']['chat'], text='Media found, this is not supported yet.') else: self.update_id = update_message['update_id'] self.message = Message( message_id=update_message['message']['message_id'], date=update_message['message']['date'], chat=update_message['message']['chat'], text=update_message['message']['text']) def __str__(self): return '{}[{}] {}\n'.format( datetime.datetime.now().__str__(), self.update_id, self.message.__str__().encode('unicode-escape'))
def send_message(): try: if request.method == 'GET': return render_template('./sendmessage.html', title="Send Message") elif request.method == 'POST': values = request.form # Check that the required fields are in the POST'ed data required = ['sender', 'private_key', 'message'] if not all(values[k] != "" for k in required): return 'Missing values', 400 sender = values['sender'] sender_private_key = values['private_key'] user = users.get_user(sender) if user == "Username does not exist": return user, 400 sender_public_key = user['public_key'] msg = Message(user["username"], user['name'], values["message"], get_utc_timestamp()) # Create a new Transaction signature = blockchain.sign_transaction(sender_private_key, msg.__str__()) if len(signature) == 2: return signature[0], 400 transaction_result = blockchain.submit_transaction( sender, sender_public_key, msg.__str__(), signature) if not transaction_result: return 'Invalid Transaction!', 406 else: response = { 'message': 'Transaction will be added to Block ' + str(transaction_result), 'signature': signature } return jsonify(response), 200 except Exception as e: return "Error in format", 400
def __str__(self): return "%s |%s| [%s,%s)" % (Message.__str__(self), self.depth, self.min_key, self.max_key)