CSCSCSCSCSCSCSCSCS
CSCSCSCSCSCSCSCSCS

Reputation: 51

Send Image in Dialogflow Nodejs

How would I send an image in Dialogflow using NodeJS? I want it to work on any platform, but for now, Telegram is fine. When I try this code I get this error: UnhandledPromiseRejectionWarning: Error: Unknown response type: "{}". Note: I am not using the inline editor.

const myPicture = new Image({
                    imageURL: picture
                });
agent.add(myPicture);

Upvotes: 1

Views: 312

Answers (1)

Ricco D
Ricco D

Reputation: 7287

You're just missing the platform: parameter to send a picture via Telegram using the Image() class. Include platform: 'TELEGRAM' to specify where you are integrating the message. Initialize the object at agent.add() by calling new Image(anotherImage)

For reference here are the available key value pair for platforms. See code below:

const imageUrl = 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/02/Stack_Overflow_logo.svg/200px-Stack_Overflow_logo.svg.png';
const anotherImage = new Image({
            imageUrl: imageUrl,
            platform: 'TELEGRAM'
       });
        
agent.add(new Image(anotherImage));

Test run:

enter image description here

There are other sample code implementations as seen here. A useful example for using an image is found in this Git repository.

Upvotes: 2

Related Questions