tgalal / yowsup

The WhatsApp lib
GNU General Public License v3.0
7.06k stars 2.23k forks source link

Changing the nickname. #476

Closed chrisduerr closed 5 years ago

chrisduerr commented 9 years ago

I've read through some of the sourcecode of yowsup bot couldn't find a way to change the nickname in the demos. I'm currently at the point where I have the echo client with closed to no modification and looking for an easy way to integrate the nickname which is displayed in group chats behind the number to get changed. I hope you are able to help me with that.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

chrisduerr commented 9 years ago

Still haven't found out anything. sendAvailableForChat(self, pushname): Seems to be legacy, right?

tgalal commented 9 years ago

Yeah that's how to do it in legacy code

chrisduerr commented 9 years ago

But I need to know how to do it in the current version. Any tips where to look?

tgalal commented 9 years ago

You need to send PresenceProtocolEntity inside your layer, something like:

from yowsup.layers.protocol_presence.protocolentities import PresenceProtocolEntity

entity = PresenceProtocolEntity(name = "new nickname")
self.toLower(entity.toProtocolTreeNode())
chrisduerr commented 9 years ago

Well if it's really that easy I feel a little stupid. :D Thank you for the help I'll look into it.

chrisduerr commented 9 years ago

PresenceProtocolEntity seems to be unable to get passed to a lower level because of missing tags. So this code isn't working for me. Could be that this is my fault but I am not 100% sure because other stuff like pings seem to not work for me, too.

rusan commented 9 years ago

It works but only for contacts. But... for iphone apps on notification screen you can see this name :).

chrisduerr commented 9 years ago

Shouldn't this name be displayed when you're in a group chat with that person but you didn't add them yet? And how are you getting that to work? Because for me it's always saying something about a missing Tag?!

tgalal commented 9 years ago

@UndeadLeech you need to post more details about that missing tag. Any logs/ stacks traces?

chrisduerr commented 9 years ago

whatsappbot_name_error

This is the error I get in my cmd. For me it looks like I am doing something wrong or it shouldn't be possible to do it that way.

tgalal commented 9 years ago

if your layer sits above YowProtocolLayers, then you shouldn't do:

self.toLower(entity.toProtocolTreeNode())

Instead it should be just:

self.toLower(entity)

chrisduerr commented 9 years ago

I tried that out before and it's not returning an error. But it doesn't change the name in group chats. This is meant to change the name displayed after the number when a contact is not added, right? And if it is and should work, is there any special time I need to call it? Or should it work whenever I am logged in? Thank you for your help :) .

addodelgrossi commented 9 years ago

I have same question. I can invoke code, but my profile name is not changed.

        entity = PresenceProtocolEntity(name="Meu Novo Nome")
        self.toLower(entity)

Thank you for your help :) .

chrisduerr commented 9 years ago

So is this problem on our end or is it not 100% supporte since Yowsup 2.0?

kyc3 commented 8 years ago

Is there a possible solution to the question of changing the nickname?

bdbais commented 8 years ago

I tried but nothing work,

my code:

    @ProtocolEntityCallback("success")
    def onSuccess(self, successProtocolEntity):

        entity = PresenceProtocolEntity(name = "Bot nr 1")
        self.toLower(entity)
jroman commented 8 years ago

This is what I did:

File: yowsup/demos/cli/layer.py Method: onSuccess()

    @ProtocolEntityCallback("success")
    def onSuccess(self, entity):
        self.connected = True
        self.output("Logged in!", "Auth", prompt = False)
        self.notifyInputThread()
###########  Start of my code
        try:
           self.profile_setStatus( MY_NICK_NAME)
        except BaseException, e:
              self.output( "CATCHED Exception while setting nick name after login: %s" % (str( e),), tag = "Exception in my code")
###########  END of my code

Hope this helps

jroman

jlguardi commented 8 years ago

Changing nickname works perfectly using the code of @bdbais. The main problem is what this function does. I mean: nickname is just displayed in the official client if you don't have registered the recipient. Otherwise, this app displays your local name for the recipient.

These are the logs for mobile changing nickname:

<message to="34xxxxxx@s.whatsapp.net" type="text" id="146xxxxx-15">
...
DEBUG:yowsup.layers.logger.layer:tx:
<presence name="changed">
</presence>
[connected]:DEBUG:yowsup.layers.logger.layer:rx:
<presence from="34xxxxx@s.whatsapp.net">
</presence>
...
<message to="34xxxxxx@s.whatsapp.net" type="text" id="146xxxxx-17">

yowsup client listening:

<message type="text" notify="34xxxxxx" from="34xxxxxxxx@s.whatsapp.net" id="146xxxxx-15" t="146xxxx">...
#changed nickname
<message type="text" notify="nickname changed" from="34xxxxxxxx@s.whatsapp.net" id="146xxxxx-17" t="146xxxx">...

As you can see, notify token changes correctly.