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
