Schmavery / facebook-chat-api

Unofficial Facebook Chat API for Nodejs
MIT License
1.94k stars 597 forks source link

how to use attachments #705

Open 53R4PH1N3 opened 5 years ago

53R4PH1N3 commented 5 years ago

hello i'm new to this repository

when i use attachments in my object it says { error: 'Disallowed props: attachments' }

here's the object that put on the api.sendMessage( ... ); var msg = { body: " ", attachments: { type: "share", url: "URL", title: "TITLE", description: "DESC" } };

and base on the Documentation on attachments under that they didn't explain how to use it...

thanks

Schmavery commented 5 years ago

Ah, I think you were reading the documentation for receiving attachments. To send, check out the docs for sendMessage.

Here's an example from that section of the docs of a file upload:

const fs = require("fs");
const login = require("facebook-chat-api");

login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
    if(err) return console.error(err);

    // This example uploads an image called image.jpg
    var yourID = "000000000000000";
    var msg = {
        body: "Hey!",
        attachment: fs.createReadStream(__dirname + '/image.jpg')
    }
    api.sendMessage(msg, yourID);
});
53R4PH1N3 commented 5 years ago

@Schmavery yup i read that.. in this API we can use card attachments on user or only on the page?

thanks for the response ..

Schmavery commented 5 years ago

This api doesn't support sending card attachments, if you want to create an "official" facebook messenger bot, you probably want to use the messenger api https://developers.facebook.com/docs/messenger-platform/send-messages/template/generic

53R4PH1N3 commented 5 years ago

other than chat cards we can use this method ? heres the image link image