I'm trying to understand how to use the Yowsup library for WhatsApp. I can send message and I can receive it, but I'm interested to get the phone number to start a new chat.
In other words, will develop a computer app that can interact with WhatsApp users, for now I can do the following:
I got the access to WhatsApp server by using this command: python yowsup-cli -c config.example --requestcode sms and python yowsup-cli -c config.example --register xxx-xxx
I send message by using this command: python yowsup-cli -c config.example -s 39xxxxxxxxxx "!"
I can have an interactive conversation by using this command: python yowsup-cli -c config.example -i 39xxxxxxxxxx
Get all message I received by using this command: python yowsup-cli -c config.example -l
Now when an user send me a message how I can interact with him/her? I guess I should get the phone number form the command python yowsup-cli -c config.example -l and begin a new interactive conversation with this command: python yowsup-cli -c config.example -i 39xxxxxxxxxx in which the 39xxxxxxxxxx is the number of the user I get with the previous command.
I hope you can help me
I don't think you want to be using yowsup-cli for development purposes. I think it's intended to be a simple demo client with very limited functionality.
If you look at the yowsup-cli source code you will see it actually imports the included examples to provide the command line message functionality.
What you see inside this code is that your python yowsup-cli -c config.example -l actually calls
wa = WhatsappListenerClient(args['keepalive'], args['autoack'])
wa.login(login, password)
This example listener client on the other hand has a callback function registered to the message_received signal.
self.signalsInterface.registerListener("message_received", self.onMessageReceived)
Now if you take a closer look at this function
def onMessageReceived(self, messageId, jid, messageContent, timestamp, wantsReceipt, pushName, isBroadCast):
formattedDate = datetime.datetime.fromtimestamp(timestamp).strftime('%d-%m-%Y %H:%M')
print("%s [%s]:%s"%(jid, formattedDate, messageContent))
if wantsReceipt and self.sendReceipts:
self.methodsInterface.call("message_ack", (jid, messageId))
You can se that the jid and therefore the phone number which you say you need is on the parameter list of this signal. If you wish to interact with a user after he has sent you a message my guess would be you should store the jid or phone number in your own subscriber to this signal.
In short - don't use the the yowsup-cli per se for development. Use it as a starting point to build your own app. Good luck!
Related
I'm trying to build a sniffer for an OpenThread network using this tutorial.
I built the openthread/ot-nrf528xx binaries using the USB_trans-Flag, flashed the ot-rcp.hex-File onto a Adafruit Feather nrf52840 and disabled the MSD. After that I created a small OpenThread network with only one router and one child (Also on Adafruit Feather nrf52840 devices).
My problem now is when I try to run the sniffer.py with following command: sudo python3 sniffer.py -c 15 -u /dev/ttyACM0 --crc --no-reset --rssi | wireshark -k -i - (with -c 15 being the channel I use in the OpenThread network and -u /dev/ttyACM0 being the USB-Port where the sniffer is connected.), I get the following log output and error message:
Initializing sniffer...
CB_Unknown (3):
** (wireshark:11740) 12:27:54.470908 [Capture MESSAGE] -- Capture Start ...
CB_Unknown (3):
ERROR: failed to initialize sniffer
** (wireshark:11740) 12:27:57.356867 [Capture MESSAGE] -- Error message from child: "Data written to the pipe is neither in a supported pcap format nor in pcapng format.", "Please report this to the developers of the program writing to the pipe."
Wireshark is opened, but displays the same error message.
Can anybody tell me what I'm doing wrong? Did I miss a step or do I maybe have to set something in wireshark?
PS: I'm using Ubuntu Linux.
Thanks for any help,
Emily.
How to use this python library from the command line?
https://pypi.python.org/pypi/dkimpy
I have a raw email message I want to validate the DKIM signature.. But how.. Can't find any docs about the usage
The raw message is a string/stream
First I needed a test message, this is how I got one:
Opened Gmail and selected an email.
Clicked the vertical 3 dots on the top right side of the message view
Selected Show original
Clicked Download Original and saved it to ~/original_msg.txt
I then opened up a terminal window and made sure I was in my home directory:
$ cd ~
Then I installed dkimpy:
$ pip install dkimpy
Annoyingly, dkimverify --help didn't work, but man came to the rescue:
$ man dkimverify
dkimverify(1)
NAME
dkimverify - Script for DKIM verifying messages on stdin
DESCRIPTION
dkimverify reads an RFC822 message on standard input, and returns with exit code 0
if the signature verifies successfully. Otherwise, it returns with exit code 1.
so I verified my downloaded Gmail message:
$ cat original_msg.txt | dkimverify
signature ok
$ echo $?
0
And just to make sure it failed as expected, I created a bogus message:
$ echo "bogus-header:bogus email" > bogus_msg.txt
And then tried to validate it:
$ cat bogus_msg.txt | dkimverify
signature verification failed
$ echo $?
1
I am trying to specify inventory file in Ansible.
The help command output:
-i INVENTORY, --inventory-file=INVENTORY
specify inventory host file
(default=/usr/local/etc/ansible/hosts)
I tried to do like this:
ansible -i /Users/liu/personal/test_ansible/hosts
but it doesn't work and instead it outputs the help content once again:
➜ test_ansible ansible -i /Users/liu/personal/test_ansible/hosts
Usage: ansible <host-pattern> [options]
Options:
-a MODULE_ARGS, --args=MODULE_ARGS
module arguments
--ask-become-pass ask for privilege escalation password
-k, --ask-pass ask for SSH password
--ask-su-pass ask for su password (deprecated, use become)
-K, --ask-sudo-pass ask for sudo password (deprecated, use become)
--ask-vault-pass ask for vault password
-B SECONDS, --background=SECONDS
run asynchronously, failing after X seconds
(default=N/A)
.......
What am I missing here?
When you use the ansible command it will run ad-hoc Ansible modules rather than the more typical Ansible playbooks (which is ran by the ansible-playbook executable instead).
The ansible executable has a requirement of a "host pattern" which will match a group of remote nodes defined in the inventory.
So if we supplied an inventory file (named inventory.ini for this example) that looked like this:
[web]
web-1.example.org
web-2.example.org
[app]
app-1.example.org
app-2.example.org
app-3.example.org
[database:children]
database-master
database-slave
[database-master]
database-master.example.org
[database-child]
database-slave1.example.org
database-slave2.example.org
We could target just the web nodes by using ansible web -i /path/to/inventory.ini -m ping to get Ansible to use the ping module against the web-1.example.org and web-2.example.org.
Alternatively we could target all of the database nodes including the master and the 2 slaves by using ansible database -i /path/to/inventory.ini -m ping.
And finally, we can also target all of the servers in the inventory by using the "magic" all group that covers all of the groups in the inventory file by using ansible all -i /path/to/inventory.ini -m ping.
I found the solution:
export ANSIBLE_INVENTORY=/Users/liu/personal/test_ansible/hosts
then will be ok!
I have installed the yowsub library (the latest version ) on my device ( Ubuntu 12.04 )
also I have obtained the request code by running this command
$ ./yowsup-cli --requestcode sms --config yowsup-cli.config
and then I registered it successfully using this command
$ ./yowsup-cli --register {MY-CODE} --config yowsup-cli.config
after that I entered the returned password in the configuration file.
but when I try to send messages by this command
$ ./yowsup-cli --send {Destination phone with it's country code} "Test message" --wait --config yowsup-cli.config
I have the following exception
Disconnected because close
I tried more than solution related to this issue but the result was the same exception.
I have solved the issue by downloading a new fork of the yowsube library from this link
http://mandroslabs.com/mandrosian/
and it's now working good.
I am trying to use fabric to automate some administrative work that I am doing on a couple of servers. The general flow is the following:
SSH with local user
run: sudo su - to become root (providing local user password again)
Do the work as root :)
Unfortunately using run('sudo su -') blocks execution of the scripts and allows user input. When I type exit or Ctrl+D the scipt resumes, but without root privileges.
I have seen a similar problem in Switching user in Fabric but I am restricted to sudo su - because I am not allowed to change the /etc/sudoers file which contains the following line:
localuser ALL = /usr/bin/su -
I browsed the source of fabric trying to find a workaround but with no success.
Having faced the same problem as yours, (only sudo su - user allowed by admin, sudo -u user -c cmd not allowed), here's my working solution with fabric:
from ilogue.fexpect import expect, expecting, run
def sudosu(user, cmd):
cmd += ' ;exit'
prompts = []
prompts += expect('bash', cmd)
prompts += expect('assword:', env.password)
with expecting(prompts):
run('sudo su - ' + user)
def host_type():
sudosu('root', 'uname -s')
There are several solutions for your issue. First, you want to run commands using sudo. You can use the fabric method sudo instead of run that runs a shell command on a remote host, with superuser privileges(sudo ref).
For example, these commands are executed using sudo :
sudo("~/install_script.py")
sudo("mkdir /var/www/new_docroot", user="www-data")
sudo("ls /home/jdoe", user=1001)
result = sudo("ls /tmp/")
Another idea is that you want to wrap a set of commands (that need to be sudoed).
You can use Fabric context managers (ref) to do that. Particularly, you can use prefix or settings.
For example:
with settings(user='root'):
run('do something')
run('do another thing')
will ask you once the root password then execute commands as root.
You can tweek settings to store the password.
There is one solution for the following problem Sorry, user localuser is not allowed to execute '/usr/bin/su - -c /bin/bash -l -c pwd' as root on hostname.
You can try sudo('mkdir ~/test_fabric',shell=False). Using param shell to avoid the bash param -l.