botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Custom Telegram messages

Open byrner75 opened this issue 10 years ago • 8 comments

Is it possible to send custom telegram messages from Node.js.

I've been trying to call session.send and session.sendMessage with various parameters but no joy. The only type of message I can successfully send is text.

Here is an example of a call I'm making.

session.send( {
    "type": "Message",
    "channelData":
    {
        "method": "sendSticker",
        "parameters":
        {
            "sticker":
            {
                "url": "https://upload.wikimedia.org/wikipedia/commons/3/33/LittleCarron.gif",
                "mediaType": "image/gif"
            }
        }
    }
});

byrner75 avatar May 13 '16 23:05 byrner75

Let me have Tom weigh in. The channelData field should work.

Stevenic avatar May 14 '16 06:05 Stevenic

You still need to set the normal from, to properties like a normal message and then instead of setting text you pass the channel data

Sent from my tumbs


From: byrner75mailto:[email protected] Sent: ‎5/‎13/‎2016 4:35 PM To: Microsoft/BotBuildermailto:[email protected] Subject: [Microsoft/BotBuilder] Custom Telegram messages (#283)

Is it possible to send custom telegram messages from Node.js.

I've been trying to call session.send and session.sendMessage with various parameters but no joy. The only type of message I can successfully send is text.

Here is an example of a call I'm making.

session.send( { "type": "Message", "channelData": { "method": "sendSticker", "parameters": { "sticker": { "url": "https://upload.wikimedia.org/wikipedia/commons/3/33/LittleCarron.gif", "mediaType": "image/gif" } } } });

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHubhttps://github.com/Microsoft/BotBuilder/issues/283

tomlm avatar May 14 '16 15:05 tomlm

Tom... I add the From & To under the covers so that should be working.

Stevenic avatar May 14 '16 16:05 Stevenic

So Tom I was just looking at my code and I'm wrong. For the inline reply I'm going to just send what was passed in. For out of band replies then I'm adding all of the other fields on to the envelope.

                        if (res) {
                            this.emit('reply', reply);
                            res.send(200, reply);
                            res = null;
                        } else if (ses.message.conversationId) {
                            // Post an additional reply
                            reply.from = ses.message.to;
                            reply.to = ses.message.replyTo ? ses.message.replyTo : ses.message.from;
                            reply.replyToMessageId = ses.message.id;
                            reply.conversationId = ses.message.conversationId;
                            reply.channelConversationId = ses.message.channelConversationId;
                            reply.channelMessageId = ses.message.channelMessageId;
                            reply.participants = ses.message.participants;
                            reply.totalParticipants = ses.message.totalParticipants;
                            this.emit('reply', reply);
                            post(this.options, endpoint, '/bot/v1.0/messages', reply, (err) => {
                                if (err) {
                                    this.emit('error', err);
                                }
                            });
                        } else {
                            // Start a new conversation
                            reply.from = ses.message.from;
                            reply.to = ses.message.to;
                            this.emit('send', reply);
                            post(this.options, endpoint, '/bot/v1.0/messages', reply, (err) => {
                                if (err) {
                                    this.emit('error', err);
                                }
                            });
                        }
                    });

Stevenic avatar May 14 '16 16:05 Stevenic

Thanks for the prompt feedback guys. So I've made a couple of changes to setup the conversation and recipient coordinates in my reply however I'm still not getting a message back! The following is my the call I'm making now. I've also tried to use the sendMessage (in channelData) method also with a text parameter but still no joy.

session.send( {
    type: "Message",
    to: session.message.from,
    from: session.message.to, 
    replyToMessageId: session.message.id,
    conversationId: session.message.conversationId,
    channelConversationId: session.message.channelConversationId,
    channelMessageId: session.message.channelMessageId,
    participants: session.message.participants,
    totalParticipants: session.message.totalParticipants,
    channelData:
    {
        "method": "sendSticker",
        "parameters":
        {
            "sticker":
            {
                "url": "https://upload.wikimedia.org/wikipedia/commons/3/33/LittleCarron.gif",
                "mediaType": "image/gif"
            }
        }
    }
});

byrner75 avatar May 14 '16 18:05 byrner75

@byrner75 Looks like we had a bug in our handling of channelData for Telegram when the value was a JSON object. I've made it fix and it will be available in the next push to production. We try to update production at least once a week. If you need a workaround in the meantime, you can send the value as a stringified JSON object.

eanders-ms avatar May 15 '16 17:05 eanders-ms

Thanks for the reply, your suggested workaround works a charm.

byrner75 avatar May 16 '16 13:05 byrner75

@byrner75 The fix is now live. You should be able to send channelData as a JSON object. Serialized JSON is still supported.

eanders-ms avatar May 18 '16 20:05 eanders-ms