def send_msg(message): keys = Project.filter()[0] if keys.length == 0: return {'msg': 'Error: API key and project id must be set up before sending messages', 'status': 'failed'} try: new_msg = requests.post( 'https://api.telerivet.com/v1/projects/%s/messages/send' % keys.project_id, auth=(keys.api_key, ''), data={'to_number': message.sms_to, 'content': message.sms_body} ) message.telerivet_id = new_msg['id'] message.sent = True message.date_sent = datetime.now() message.save() return {'msg': 'Message sent and created', 'status': 'success'} except Exception, e: return {'msg': str(e), 'status': 'failed'}
def check(self): project = Project.filter() return project.length > 0 and \ project.api_key[0] != '' and \ project.project_id[0] != ''