Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello β I'm @olemoritz on Twitter.
Does this script work with the iphone app?
-
hello I would like to buy this app for iphone ... but I need to understand if this script that is used to send a message via whatsapp via the web, could work ... who can tell me something about it?
obviously for security reasons I deleted the token and the mobile number. Thank you# coding=utf-8 import csv import requests # Wassenger API key token - DO NOT CHANGE! token = '_______________________________________' # Wassenger API - DO NOT CHANGE! baseUrl = 'https://api.wassenger.com/v1' # IMPORTANT: message to send, edit the text as needed message = ''' Prova messaggio ''' # Image to send in messages # TODO: update the URL to the one you want, if needed send_image = False # Sample image to send, if send_image enabled image_url = 'https://i.imgur.com/bkQ1v1a.jpg' if send_image else None # IMPORTANT: paste the list of numbers between the quotes one per line csv_data = ''' Phone ___________________ ''' def read_csv(): csv_reader = csv.reader(csv_data.split('\n'), delimiter=',') return [ { 'phone': '+{}'.format(row[0]), 'message': message } for index, row in enumerate(list(csv_reader)) if index > 1 and row and len(row) >= 1 and row[0] ] def upload_file(image_url): files = {'url': image_url} url = baseUrl + '/files' response = requests.post(url, headers={'token': token}, json=files) if response.status_code >= 400: raise Exception('Cannot upload file:', response.status_code, response.text) media_id = response.json().pop()['id'] print 'Media file uploaded successfully with ID:', media_id return media_id def send_message(message, media_id): payload = { 'phone': message['phone'], 'message': message['message'] } if media_id: payload['media'] = { 'file': media_id, 'message': message['message'] } print 'Sending message to', message['phone'], 'with text:',payload['message'] url = baseUrl + '/messages' response = requests.post(url, json=payload, headers={'content-type': 'application/json', 'token': token}) # Check API response and show a message if response.status_code < 400: print 'Message queued successfully with ID:', response.json()['id'] else: print '[error] Message failed:', response.status_code, response.json() # Compose messages to send from CSV data messages = read_csv() print 'Sending total messages:', len(messages) # Upload media file, if needed media_id = upload_file(image_url) if image_url else None # Iterate all messages in order to send them sequentially for message in messages: # Send message via API send_message(message, media_id) print '' print 'All messages sent :)'
Currently this code works by entering this code on the repl.it website
-
@martinoimp this should work but I can't try. If I want to get a token, I have to signup and to give my credit card number, even for the 7days trial π₯
For your info: if you want to post source code, for the readability, you have to insert it between 2 lines of triple back quotes (or use the </> button above).
#coding=utf-8 import csv import requests #Wassenger API key token - DO NOT CHANGE! token = 'xxx' #Wassenger API - DO NOT CHANGE! baseUrl = 'https://api.wassenger.com/v1' #IMPORTANT: message to send, edit the text as needed message = ''' test ''' #Image to send in messages #TODO: update the URL to the one you want, if needed send_image = False #Sample image to send, if send_image enabled image_url = 'https://i.imgur.com/bkQ1v1a.jpg' if send_image else None #IMPORTANT: paste the list of numbers between the quotes one per line csv_data = ''' nnnnnnnnnnnn ''' def read_csv(): csv_reader = csv.reader(csv_data.split('\n'), delimiter=',') arr = [] for index, row in enumerate(list(csv_reader)): if index >= 0 and row and len(row) >= 1 and row[0]: arr.append({'phone': '+{}'.format(row[0]),'message': message}) return arr def upload_file(image_url): files = {'url': image_url} url = baseUrl + '/files' response = requests.post(url, headers={'token': token}, json=files) if response.status_code >= 400: raise Exception('Cannot upload file:', response.status_code, response.text) media_id = response.json().pop()['id'] print(('Media file uploaded successfully with ID:', media_id)) return media_id def send_message(message, media_id): payload = { 'phone': message['phone'], 'message': message['message'] } if media_id: payload['media'] = { 'file': media_id, 'message': message['message'] } print('Sending message to', message['phone'], 'with text:',payload['message']) url = baseUrl + '/messages' response = requests.post(url, json=payload, headers={'content-type': 'application/json', 'token': token}) #Check API response and show a message if response.status_code < 400: print('Message queued successfully with ID:', response.json()['id']) else: print('[error] Message failed:', response.status_code, response.json()) #Compose messages to send from CSV data messages = read_csv() print(messages) print('Sending total messages:', len(messages)) #Upload media file, if needed media_id = upload_file(image_url) if image_url else None #Iterate all messages in order to send them sequentially for message in messages: #Send message via API send_message(message, media_id) print('') print('All messages sent :)')
-
Ok, I have taken the risk, I gave my credit card number (you are responsible if they steal me π) and the script works with
[{'phone': '+nnnnnnnnn', 'message': '\ntest\n'}] Sending total messages: 1 Sending message to +nnnnnnnnnn with text: test Message queued successfully with ID: xxxxxxxxxxxxxxx All messages sent :)
But message not yet arrived on my iPhone, wait, pray and (perhaps) see
-
can you confirm that with the iphone app it works ?? so I immediately proceed with the purchase
-
@martinoimp I can not confirm more than you see above.
Your script (a little bit modified) runs without returned error from the request and you can see on your account of the server that a message was in wait.
To avoid problems with my credit card, I deleted my account after some waiting time.Γdit: I don't see any reason for to working
Edit: perhaps the wait is due to the fact that I try to send a message to the telephone number where I created the QR
-
-
@martinoimp All what you see in my posts have been done in Pythonista
-
hi I tried the code .. but purposely it doesn't work .. it tells me a syntax error
@cvp# coding=utf-8 import csv import requests # Wassenger API key token - DO NOT CHANGE! token = '-' # Wassenger API - DO NOT CHANGE! baseUrl = 'https://api.wassenger.com/v1' # IMPORTANT: message to send, edit the text as needed message = ''' Buongiorno domani siamo in zona. Ha bisogno di qualcosa di acqua ? ''' # IMPORTANT: paste the list of numbers between the quotes one per line csv_data = ''' Phone - ''' def read_csv(): csv_reader = csv.reader(csv_data.split('\n'), delimiter=',') return [ { 'phone': '+{}'.format(row[0]), 'message': message } for index, row in enumerate(list(csv_reader)) if index > 1 and row and len(row) >= 1 and row[0] ] def send_message(message, media_id): payload = { 'phone': message['phone'], 'message': message['message'] } if media_id: payload['media'] = { 'file': media_id, 'message': message['message'] } print ('Sending message to', message['phone'], 'with text:',payload['message']) url = baseUrl + '/messages' response = requests.post(url, json=payload, headers={'content-type':'application/json', 'token': token}) # Check API response and show a message if response.status_code < 400: print ('Message queued successfully with ID:', response.json()['id']) else: print ('[error] Message failed:', response.status_code, response.json()) # Compose messages to send from CSV data messages = read_csv() print ('') print ('Sending total messages:', len(messages)) media_id = upload_file(image_url) if image_url else None for message in messages: send_message(message, media_id) print ('') print ('All messages sent :)β)
-
@martinoimp I see some errors:
- the call to send_message was not indented
for message in messages: send_message(message, media_id)
- the end quote was not a real quote
print ('All messages sent :)')
- image_url variable does not exist
media_id = upload_file(image_url) if image_url else None
After these corrections, the script prints
Sending total messages: 1