Igbot: Direct message

Created on 26 Jan 2017  路  26Comments  路  Source: ohld/igbot

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.

enhancement

All 26 comments

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.

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',
        ];

...

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

The same with other arguments (recipient_users)

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.

Are you sure that PHP version works?

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

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

Hello everybody!

Any news about this issue? Is it working?

袟写褉邪胁褋褌胁褍泄褌械.
袣邪泻 蟹邪锌褍褋褌懈褌褜 斜芯褌邪????

Up! :+1:

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. :(

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

@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)

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

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

@marcelinhovt You can find all parameters here

@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'])

@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...

@marcelinhovt you need System.Guid.NewGuid()

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 }
            };

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

Does anyone here have the cURL request for this?

@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!

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

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iransales picture iransales  路  8Comments

balochlens picture balochlens  路  5Comments

TiasTias picture TiasTias  路  9Comments

iransales picture iransales  路  4Comments

spctra picture spctra  路  9Comments