yakyak / hangupsjs

google hangouts client library for nodejs
226 stars 46 forks source link

Where to find the chat_ids? #65

Open Konstantinusz opened 7 years ago

Konstantinusz commented 7 years ago

Are they the Google+ IDs?

My code is the following, its purpose is nothing but sending an image together with a text "hi", but unfortunately doesn't work:

#!/usr/bin/node
var Client = require('hangupsjs');
var Q = require('q');
var path=require('path');
var fp=path.resolve(process.argv[2])
console.log(fp)
// callback to get promise for creds using stdin. this in turn
// means the user must fire up their browser and get the
// requested token.
var creds = function() {
  return {
    auth: Client.authStdin
  };
};

var client = new Client();

// set more verbose logging
client.loglevel('info');

// receive chat message events
client.on('chat_message', function(ev) {
  return console.log(ev);
});

// connect and post a message.
// the id is a conversation id.
client.connect(creds).then(function() {
    client.uploadimage(fp, null, 30000).then(
       function(image_id){
           console.log("image_id: "+image_id);
           client.createconversation([109444762308105529580]).then(function(conversation_obj){
              console.log("conversation_id: "+JSON.stringify(conversation_obj, null, 4));
              client.sendchatmessage(conversation_obj.conversation.id.id,
             [[0, 'hi']],image_id).then(function(res){JSON.stringify(res, null, 4)},function(res){JSON.stringify(res, null, 4)},function(res){JSON.stringify(res, null, 4)}).done();
            }
           )

        }
    );
}).done();

Image is uploaded, its ID is printed, but conversation with the person isn't created. I don't know why.

Konstantinusz commented 7 years ago

Works now, I had to use client.createconversation(["109444762308105529580"])

instead of

client.createconversation([109444762308105529580])