Giter Site home page Giter Site logo

yowsup-microservice's Introduction

NEWS 20180327

The media branch has image recibe (and some other media) capabilities. Also reconnect and minor imporovements. Thanks to all colaborators.

Media version docker image

gabrieltandil/yowsup-microservice:media

yowsup-microservice

This Project provides a microservice which implements an interface to yowsup2. You can Send/Receive Whatsapp-Messages with any language of your choice.

Prerequisites

Install & Configure the yowsup2 CLI Demo.

Use yowsup-cli to register a Number.

Without Docker

Installation (General)

  1. Install rabbitmq
  2. Install Flask,Nameko,Flasgger,pexpect
  3. Install yowsup2

Installation (on Ubuntu)

# Install Python Stuff:
sudo apt-get install python3-pip python3-dev
pip3 install nameko
pip3 install flask
pip3 install flasgger
pip3 install pexpect
# git+https://github.com/tgalal/yowsup@master works fine
pip3 install git+https://github.com/tgalal/yowsup@master 

# Install RabbitMQ
apt-get install rabbitmq-server

Configuration

rename service.yml.sample to service.yml and put your credentials into it.

Usage

Run the the Service with:

startservice.sh

Run the the Api with:

startapi.sh

Send

Go to: http://127.0.0.1:5000/apidocs/index.html

Recive

Set the parameter ENDPOINT_RESEND_MESSAGES to the url of your application where you want the messages to be dispatched. The received messages will be sent to that url in JSON format.

{{"from":"{FROM}","to":"{TO}","time":"{TIME}","id":"{MESSAGE_ID}","message":"{MESSAGE}","type":"{TYPE}"}}

Example Messages for other Integrations:

Have a look at swagger documentation.

Debugging

Run

nameko shell
n.rpc.yowsup.send(type="simple", body="This is a test Message!", address="49XXXX")

Using Docker to run in a container

This will automatically setup and run the main service and the API The service is exposed in port 80

Change the following environment variables with your credentials (after registering on yowsup-cli) in env.list file. Or create a new env.list file

USERNAME=<your_account_number>
PASSWORD=<your_password>
TOKEN_RESEND_MESSAGES=<your_token_resend_messages>
ENDPOINT_RESEND_MESSAGES=<your_endpoint_resend_messages>
  • TOKEN_RESEND_MESSAGES: any value established by you that will be sent in the request to validate the identity.
  • ENDPOINT_RESEND_MESSAGES: the url where messages received from the whatsapp network will be sent in the specified json format.

Then run:

docker run --name <name> --env-file env.list -p <hostPort>:80 gabrieltandil/yowsup-microservice:latest

And you're all set!! :D

Build docker image

docker build -t yowsup-microservice:latest .

yowsup-microservice's People

Contributors

eliaskotlyar avatar gabriel-tandil avatar jcgruenhage avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yowsup-microservice's Issues

Multi-line Messages or Messages having double quotes (") not working.

Hey , i'm using this Microservice and working on something taking it as base. I've found that if someone sends Multiline message or Message containing double quotes the json string sent to server becomes an invalid json format. It just breaks. Please look into it and come up with any other encoding that works for it well. I tried replacing " with " but that didn't worked either.

Start Service : No module named src.yowsupextension

root@whats:/var/www/html/yowsup-microservice# nameko run --config ./serviceconfig.yml service
Traceback (most recent call last):
File "/usr/local/bin/nameko", line 11, in
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/nameko/cli/main.py", line 107, in main
args.main(args)
File "/usr/local/lib/python2.7/dist-packages/nameko/cli/commands.py", line 110, in main
main(args)
File "/usr/local/lib/python2.7/dist-packages/nameko/cli/run.py", line 181, in main
import_service(path)
File "/usr/local/lib/python2.7/dist-packages/nameko/cli/run.py", line 46, in import_service
import(module_name)
File "./service.py", line 5, in
from src.yowsupextension import YowsupExtension
ImportError: No module named src.yowsupextension

I have all the requirements installed.

Any help, thank you.

Need guidance in installation. Thank you very much for your time

Dear seniors, i am having problem in the installation. I seem like cannot run the server online. Feel free to give some guidance. Thank you!

bot@bot-Aspire-V5-471PG:~/Desktop/goh_yowsup_microservice$ ./startservice.sh
starting services: yowsup
Starting YowsUP...XXXXXXX.
Connected to amqp://guest:**@127.0.0.1:5672//
Logged in!
Iq:
ID: 1
Type: result
from: [email protected]

Iq:
ID: 2
Type: result
from: [email protected]

Iq:
ID: 3
Type: result
from: [email protected]

I stuck at step below:
bot@bot-Aspire-V5-471PG:~/Desktop/yowsup_microservice$ sudo ./startapi.sh

  • Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
    127.0.0.1 - - [03/Nov/2017 01:50:51] "GET / HTTP/1.1" 404 -
    127.0.0.1 - - [03/Nov/2017 01:50:51] "GET /favicon.ico HTTP/1.1" 404 -
    127.0.0.1 - - [03/Nov/2017 01:50:54] "GET / HTTP/1.1" 404 -

Error with Startapi

Hi I was trying to run the startapi.sh but i got this error:
Traceback (most recent call last): File "/home/ubuntu/workspace/myenv/lib/python3.5/site-packages/flask/app.py", line 1982, in wsgi_app response = self.full_dispatch_request() File "/home/ubuntu/workspace/myenv/lib/python3.5/site-packages/flask/app.py", line 1614, in full_dispatch_request rv = self.handle_user_exception(e) File "/home/ubuntu/workspace/myenv/lib/python3.5/site-packages/flask/app.py", line 1517, in handle_user_exception reraise(exc_type, exc_value, tb) File "/home/ubuntu/workspace/myenv/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise raise value File "/home/ubuntu/workspace/myenv/lib/python3.5/site-packages/flask/app.py", line 1612, in full_dispatch_request rv = self.dispatch_request() File "/home/ubuntu/workspace/myenv/lib/python3.5/site-packages/flask/app.py", line 1598, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/home/ubuntu/workspace/myenv/lib/python3.5/site-packages/flasgger/utils.py", line 216, in wrapper return function(*args, **kwargs) File "./api.py", line 22, in send with ClusterRpcProxy(CONFIG) as rpc: File "/home/ubuntu/workspace/myenv/lib/python3.5/site-packages/nameko/standalone/rpc.py", line 224, in __enter__ return self.start() File "/home/ubuntu/workspace/myenv/lib/python3.5/site-packages/nameko/standalone/rpc.py", line 230, in start self._reply_listener.setup() File "/home/ubuntu/workspace/myenv/lib/python3.5/site-packages/nameko/rpc.py", line 250, in setup self.queue_consumer.register_provider(self) File "/home/ubuntu/workspace/myenv/lib/python3.5/site-packages/nameko/standalone/rpc.py", line 119, in register_provider verify_amqp_uri(amqp_uri) File "/home/ubuntu/workspace/myenv/lib/python3.5/site-packages/nameko/amqp/utils.py", line 49, in verify_amqp_uri with transport.establish_connection(): File "/home/ubuntu/workspace/myenv/lib/python3.5/site-packages/kombu/transport/pyamqp.py", line 116, in establish_connection conn = self.Connection(**opts) File "/home/ubuntu/workspace/myenv/lib/python3.5/site-packages/nameko/amqp/utils.py", line 26, in __init__ super(ConnectionTester, self).__init__(*args, **kwargs) File "/home/ubuntu/workspace/myenv/lib/python3.5/site-packages/amqp/connection.py", line 165, in __init__ self.transport = self.Transport(host, connect_timeout, ssl) File "/home/ubuntu/workspace/myenv/lib/python3.5/site-packages/amqp/connection.py", line 186, in Transport return create_transport(host, connect_timeout, ssl) File "/home/ubuntu/workspace/myenv/lib/python3.5/site-packages/amqp/transport.py", line 299, in create_transport return TCPTransport(host, connect_timeout) File "/home/ubuntu/workspace/myenv/lib/python3.5/site-packages/amqp/transport.py", line 95, in __init__ raise socket.error(last_err) OSError: [Errno 111] Connection refused

Maybe i didn't set the config properly can you help me with this? I am new in python

cannot find service.yml

hi
yowsup-cli 2 is installed and working fine.
after that i followed the yowsup-microservice

Installed Python Stuff:

sudo apt-get install python3-pip python3-dev
pip3 install nameko
pip3 install flask
pip3 install flasgger
pip3 install git+https://github.com/tgalal/yowsup@master

Install RabbitMQ

apt-get install rabbitmq-server

installed all the above packages but i could not find service.yml.sample file.
rename "service.yml.sample to "service.yml" and put your credentials into it.
not even with
find / -name service.yml.sample

am i missing something ?
thanks

How to broadcast?

Do any one know how to implement broadcast. How I put this snippet?

def message_broadcast(self, numbers, content):
    if self.assertConnected():
        jids = [self.aliasToJid(number) for number in numbers]
        outgoingMessage = BroadcastTextMessage(jids, content)
        self.toLower(outgoingMessage)

How can we set presence and ping the server?

This repo works perfect and the queue system is amazing. However, I was wondering how can we send the presence and ping command.

P.S: I know its not a fully fledged one like the main repo, but I wanted to send presence and pings optionally so that my bot might seem real. Now my last seen was long back and am sending messages.

how to send image?

how to send image?

I can send text using n.rpc.yowsup.send(type="simple", body="This is a test Message!", address="91XXXXXXX")

I try n.rpc.yowsup.send(type="image", body="/root/test/space.jpg", address="91XXXXXXX") it returns True but do not deliver image.

Error: argument should be a bytes-like object or ASCII string, not 'NoneType

Hi Elias
we have install and configure , but I'm getting this error RUN command : sh startservice.sh
starting services: yowsup
Starting YowsUP...
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/eventlet/hubs/hub.py", line 458, in fire_timers
timer()
File "/usr/local/lib/python3.5/dist-packages/eventlet/hubs/timer.py", line 58, in call
cb(*args, **kw)
File "/usr/local/lib/python3.5/dist-packages/eventlet/greenthread.py", line 218, in main
result = function(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/nameko/utils/init.py", line 176, in call
return getattr(item, name)(*args, **kwargs)
File "./src/yowsupextension.py", line 37, in setup
self.stack.setCredentials(credentials)
File "/usr/local/lib/python3.5/dist-packages/yowsup/stacks/yowstack.py", line 156, in setCredentials
self.getLayerInterface(YowAuthenticationProtocolLayer).setCredentials(*credentials)
File "/usr/local/lib/python3.5/dist-packages/yowsup/layers/auth/layer_interface_authentication.py", line 5, in setCredentials
self._layer.setCredentials((phone, password))
File "/usr/local/lib/python3.5/dist-packages/yowsup/layers/auth/layer_authentication.py", line 46, in setCredentials
self._credentials = self.__getCredentials(credentials)
File "/usr/local/lib/python3.5/dist-packages/yowsup/layers/auth/layer_authentication.py", line 41, in __getCredentials
password = base64.b64decode(pb64)
File "/usr/lib/python3.5/base64.py", line 81, in b64decode
s = _bytes_from_decode_data(s)
File "/usr/lib/python3.5/base64.py", line 46, in _bytes_from_decode_data
"string, not %r" % s.class.name) from None
TypeError: argument should be a bytes-like object or ASCII string, not 'NoneType'

'bytes' object has no attribute 'encode'

I am successfully able to start service and receiving message but suddenly i see this in log and whatsapp exits immediately!

'bytes' object has no attribute 'encode'
Whatsapp exited

After some minutes stops working

Hi,

This project worked very well. But after some random minutes it gets disconected and stops working.
The logs are:

[Errno 110] Connection timed out
Whatsapp exited

And when a try to send a whatsApp it don't work and print:

Not connected

These log messages comes from the process:
nameko run --config ./serviceconfig.yml service

Anyone could help?

Error connecting to broker

Hi, I just tried to download and use the microservice but I'm getting this error:

starting services: yowsup
Starting YowsUP...
Trying to connect via xxxxxxx:XXXXXXXXXXXXXXXXXXXXX
Exception was thrown
debug information:
<pexpect.pty_spawn.spawn object at 0x7fae59fae898>
command: /usr/local/bin/yowsup-cli
args: ['/usr/local/bin/yowsup-cli', 'demos', '--yowsup', '--login', 'xxxxxxx:XXXXXXXXXXXXXXXXXXXXX']
buffer (last 100 chars): b'/L\r\n'
before (last 100 chars): b'/L\r\n'
after: <class 'pexpect.exceptions.TIMEOUT'>
match: None
match_index: None
exitstatus: None
flag_eof: False
pid: 8
child_fd: 6
closed: False
timeout: 30
delimiter: <class 'pexpect.exceptions.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1
Error connecting to broker at pyamqp://guest:guest@localhost ([Errno 111] ECONNREFUSED).
Retrying in 2.0 seconds.
Error connecting to broker at pyamqp://guest:guest@localhost ([Errno 111] ECONNREFUSED).
Retrying in 4.0 seconds.
Error connecting to broker at pyamqp://guest:guest@localhost ([Errno 111] ECONNREFUSED).
Retrying in 6.0 seconds.

Broadcast message

Hi Elias
Thanks for the wonderful code, i am trying to send to multiple users, and i have tried several versions of yowsup but unfortunately could not figure out a way to send broadcast messages.

Can you help me on how to use the function if exists.

ImportError: No module named 'yowsup'

I do not know what the mistake is?
Need help: D

./startservice.sh

Traceback (most recent call last):
  File "/usr/local/bin/nameko", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.5/dist-packages/nameko/cli/main.py", line 66, in main
    args.main(args)
  File "/usr/local/lib/python3.5/dist-packages/nameko/cli/commands.py", line 85, in main
    main(args)
  File "/usr/local/lib/python3.5/dist-packages/nameko/cli/run.py", line 179, in main
    import_service(path)
  File "/usr/local/lib/python3.5/dist-packages/nameko/cli/run.py", line 46, in import_service
    __import__(module_name)
  File "./service.py", line 5, in <module>
    from src.yowsupextension import YowsupExtension
  File "./src/yowsupextension.py", line 7, in <module>
    from yowsup.layers.network import YowNetworkLayer
ImportError: No module named 'yowsup'

Problem with receiving image

I am using media branch of code but still getting problem in receiving image.

InvalidMessage or KeyId for 918433442835, going to send a retry

Whenever i get image it is going in InvalidMessageException in layer_receive.py so getting this message.
I haven't changed any code at layer_receive.py
Any guess what could be wrong?

'NoneType' object has no attribute 'getChild' Whatsapp exited

Everyday it stops working with messages like this:

Send Message to 551186853836 : Olá, falo da Hospital Santa Catarina e gostaria de confirmar a consulta de Suda com o Doutor Dozol Amanhã, 08/12/2017 as 10:00. Podemos confirmar? 172.17.0.1 - - [07/Dec/2017 10:48:23] "POST /send HTTP/1.1" 200 - 'NoneType' object has no attribute 'getChild' Whatsapp exited

Any one know how to solve this?

Proper use of this API?

Hi there,
would it be advisable to use this tool in an enterprise environment?
My job is in risk

Read Message from ENDPOINT_RESEND_MESSAGES

How i read Message from ENDPOINT_RESEND_MESSAGES ??
my end point like this
ENDPOINT_RESEND_MESSAGES: 'http://example.com/message'
i dont show message from my message folder.
sorry if i m misunderstanding...

My Config example

AMQP_URI: 'pyamqp://guest:guest@localhost'
WEB_SERVER_ADDRESS: '77.41.51.112:80'
YOWSUP_USERNAME: '62858000000'
YOWSUP_PASSWORD: 'ABCD6o3HcMdas@asdahug='
TOKEN_RESEND_MESSAGES: 'mytoken'
ENDPOINT_RESEND_MESSAGES: 'http://example.com/message'
rpc_exchange: 'nameko-rpc'
max_workers: 1
parent_calls_tracked: 10

blocked using docker version

I was testing docker version for a simple question-answer bot, it was blocked in about 2 days.
Anyone else have better luck?

Stream Error type: ack {'ack': None}

When server start approx after 15th or 18th iq i see on console

Stream Error type: ack
{'ack': None}
Initiating reconnect
Disconnected: Connection Closed

and connection get terminated, i have tried one retry loop but do we know why this problem keeps on poping?

File not found when send media

I am trying to sent whatsapp message with image.

But , get error file not found.

file-not-found-whatsapp

And guide about how to solve this ? By looking at the code , it is a file that being used by this library to sent to whatsapp as a media.

But , that file is not exist.

"Unhandled" to receive audio messages

When I send audio messages from my WhatsApp to my server I get the following error:
"Unhandled"

And my endpoint is not called.

Are recorded voice messages supported?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.