1

I'm looking for a solution since few times to generate automatic answers to people which are answering me to my private messages on LinkedIn.

Knowing that I am a beginner in python (I would prefer to use python), what would be the best strategy to automate my responses with Linkedin?

FrancNovation
  • 349
  • 6
  • 20

1 Answers1

0

I suggest you use DialogFlow and connect it to the Linkedin API. You can see more functions of the Linkedin API.

You can see the code to connect the Linkedin API below:

return await require("@pipedreamhq/platform").axios(this, {
  url: `https://api.linkedin.com/v2/me`,
  headers: {
    Authorization: `Bearer ${auths.linkedin.oauth_access_token}`,
  },
})

Additionally, you can see official documentation about the Linkedin API here.

There are more solutions to automate, but you have to pay monthly, like hootsuite or expandi.io.

You can see these tutorials of how to use DialogFlow CX.

EDIT

You should use linkedin API directly. There a lot of information about it.

You can see this code example to send message.

function message($subject, $body, $recipients)
{
    if (!is_array($recipients)) {
        throw new Exception('Recipients must be suplied as an array');
    }

    // Start document
    $xml = new DOMDocument('1.0', 'utf-8');

    // Create element for recipients and add each recipient as a node
    $elemRecipients = $xml->createElement('recipients');
    foreach ($recipients as $recipient) {
        // Create person node

        $person = $xml->createElement('person');
        $person->setAttribute('path', '/people/' . (string) $recipient);

        // Create recipient node
        $elemRecipient = $xml->createElement('recipient');
        $elemRecipient->appendChild($person);

        // Add recipient to recipients node
        $elemRecipients->appendChild($elemRecipient);

    }


    // Create mailbox node and add recipients, body and subject
    $elemMailbox = $xml->createElement('mailbox-item');
    $elemMailbox->appendChild($elemRecipients);
    $elemMailbox->appendChild($xml->createElement('body', ($body)));
    $elemMailbox->appendChild($xml->createElement('subject', ($subject)));

    // Append parent node to document
    $xml->appendChild($elemMailbox);

    $response = fetch('POST','/v1/people/~/mailbox', $xml->saveXML());

    return ($response);
}


function fetch($method, $resource, $body = '') {
    $params = array('oauth2_access_token' => $_SESSION['access_token'],
        'format' => 'json',
    );

    // Need to use HTTPS
    $url = 'https://api.linkedin.com' . $resource . '?' . http_build_query($params);
    // Tell streams to make a (GET, POST, PUT, or DELETE) request


    $context = stream_context_create(
        array('http' =>
            array('method' => $method,

                'header'=> "Content-Type:text/xml\r\n"
                    . "Content-Length: " . strlen($body) . "\r\n",
                'content' => ($body)
            )
        )
    );


    // Hocus Pocus
    $fp = fopen($url, 'r', false, $context);
    $response = file_get_contents($url, false, $context);
    $result =json_decode($response,true);

    return $result;}
message('Subject', 'body', array('id'));

Uses a linkedin "user ids" (array of ids).

You can se more code examples in Python, starting from the begining to make a connection to python.

Raul Saucedo
  • 1,614
  • 1
  • 4
  • 13
  • Thank you a lot for your help. I don't see any linkedin API in pipedream to answer private message with dialogflow. Would you have a recommandation to give me ? Should I use linkedin API directly without using pipedream ? (I'm juste discovering pipedream) – FrancNovation Oct 28 '21 at 05:05
  • @FrancNovation I add more information. – Raul Saucedo Oct 28 '21 at 12:38