ohld / igbot

🐙 Free scripts, bots and Python API wrapper. Get free followers with our auto like, auto follow and other scripts!
https://hikerapi.com/p/N2P6iqiM
Apache License 2.0
4.71k stars 1.47k forks source link

Direct message #18

Closed mafa89 closed 7 years ago

mafa89 commented 7 years ago

Hello! I tried to implement direct messages by adding

def direct_message(self, userid,messagestxt):
    data = json.dumps({
    'recipient_users'   : str(userid)
    'client_context'    : str(self.uuid),
    '_uuid'             : str(self.uuid),
    '_uid'              : str(self.username_id),
    '_csrftoken'        : str(self.token),
    'thread_ids'        : '0',
    'text'              : 'test message',
    })
    print self.SendRequest('direct_v2/threads/broadcast/text/', self.generateSignature(data))
    print self.LastJson

and I get on the console, from the "print" commands:

Request return 400 error! False {u'status': u'fail', u'message': u'Text is missing'}

Do you have any idea / suggestion to make direct messages working? Thank you.

ohld commented 7 years ago

Are you sure that param name for message text is "text"? May be it has another name so Instagram parser can't find message text.

mafa89 commented 7 years ago

I got inspired by the php code, which reads like:

...
        $endpoint = 'direct_v2/threads/broadcast/text/';
        $boundary = $this->parent->uuid;
        $bodies = [
            [
                'type' => 'form-data',
                'name' => 'recipient_users',
                'data' => "[[$recipient_users]]",
            ],
            [
                'type' => 'form-data',
                'name' => 'client_context',
                'data' => $this->parent->uuid,
            ],
            [
                'type' => 'form-data',
                'name' => 'thread_ids',
                'data' => '["0"]',
            ],
            [
                'type' => 'form-data',
                'name' => 'text',
                'data' => is_null($text) ? '' : $text,
            ],
        ];

        $data = $this->buildBody($bodies, $boundary);
        $headers = [
            'Proxy-Connection: keep-alive',
            'Connection: keep-alive',
            'Accept: */*',
            'Content-Type: multipart/form-data; boundary='.$boundary,
            'Accept-Language: en-en',
        ];

...
ohld commented 7 years ago

May be you should pass thread_ids param as list of one value not as a simple value? As at the php example.

ohld commented 7 years ago

The same with other arguments (recipient_users)

mafa89 commented 7 years ago

I tried several different requests, including the suggestion you proposed, but without any luck :( If someone will manage to try this out, and find a solution, please let me know! Thank you.

ohld commented 7 years ago

Are you sure that PHP version works?

mafa89 commented 7 years ago

I did not try the PHP version personally, but the authors told me it is working...

ohld commented 7 years ago

If the original version is not working, you don't need to try the same in python :) But I appreciate your Idea and test. Maybe someone will continue your research

edrizo commented 7 years ago

Hello everybody!

Any news about this issue? Is it working?

oleglaran commented 7 years ago

Здравствуйте. Как запустить бота????

Perados commented 7 years ago

Up! :+1:

Perados commented 7 years ago

Any news on this? I tried to implement the direct message method without much success. I thought I could use the direct_share method as a template, but that method is also broken. I get:

api.direct_share("XXXXXXXXXXXXXX", "XXXXXXXXXX", 'Hello')
{u'message': u'Thread does not exist', u'status': u'fail'}

Trying to implement the direct message one, I get: {u'message': u'Text is missing', u'status': u'fail'}

The same as @mafa89 . I also tried many different combinations for the request, nothing worked. :(

sudoguy commented 7 years ago

@mafa89 @Perados @edrizo I'll add methods for direct messaging in next few days

sudoguy commented 7 years ago

@mafa89 @Perados @edrizo Now you can send messages. https://github.com/instagrambot/instabot/commit/ce98922a56b524aef70cd65fe1308280d72514f1 Example:

user_ids = ['user_one', 'user_two', 'user_three']

# send_message will create group with message "Hello" 
bot.send_message('Hello', user_ids)

# send_messages will send message for every user in list personally 
bot.send_messages('Hello, user_ids)
Perados commented 7 years ago

@sudoguy Thank you! I will test this tonight and let you know how it goes! Cheers!

mcferdev commented 7 years ago

Hello. Is this working? @sudoguy , wich parameters do you send when send the post ?? I am trying to send from my client, but using the instagram api directly and i cannot discover the parameters that needs to put in the body. I appreciate if you explain me.

Thanks

sudoguy commented 7 years ago

@marcelinhovt You can find all parameters here

Perados commented 7 years ago

@sudoguy @marcelinhovt Works like a charm. Using it in production now. Thank you very much! 👍 I use it like this :

        instabot.send_message('Hello', ['12345'])
mcferdev commented 7 years ago

@Perados @sudoguy Nice!! What does the str(uuid.uuid4()) ?? Because in my functions i did not need yet to pass any uuid ! So, i don´t understand how build this uuid to send... For direct message i am seeing that is a lot of fields...

sudoguy commented 7 years ago

@marcelinhovt you need System.Guid.NewGuid()

imchegeni commented 7 years ago

please put your successful code here. I'm trying to write same code in c# & was success in follow, unfollow, like & comment. but can't send direct.

my code response is Error 400, text is missing

i used this dictionary:

var dic = new Dictionary<string, string>
            {
                { "text" ,     Text},
                {"recipient_users", "[" + UserId +"]" },
                {"action" , "send_item" },
                {"client_context",  Theclient_context },
                {"_csrftoken",    csrftoken},
                { "_uuid",         guid },
                {"_uid",          ds_user_id }
            };
Hiwakea commented 6 years ago

So, copy and paste what into what? I'm totally lost, please help.. I want to auto DM to my new followers :)

macdonjo commented 6 years ago

Does anyone here have the cURL request for this?

edrizo commented 6 years ago

@mafa89 @Perados @edrizo I'll add methods for direct messaging in next few days

@sudoguy Hi! Is it working?

How can we use it? :-)

Thank you so much!

Gordiy commented 5 years ago

direct_v2/threads/direct_v2_thread_id/items/%s/delete/ what I must set instead of %s

nbgabriel commented 5 years ago

So, copy and paste what into what? I'm totally lost, please help.. I want to auto DM to my new followers :)

+1!

We will appreciate any help to auto DM new followers!, Thanks folks!