windkh / node-red-contrib-telegrambot

Telegram bot nodes for node-red.
Other
269 stars 119 forks source link

Flow perfectly works with telegram node v4.4.0, but fails with new version 5.1.5 #63

Closed fmanclossi closed 5 years ago

fmanclossi commented 5 years ago

I've the following flow that works like a charm with v4.4.0 but stop working with 5.1.5 What is changed about "voice messages"? How can I fix it? [ { "id": "b4106ec1.63dd58", "type": "tab", "label": "Telegram", "disabled": false, "info": "" }, { "id": "d1198164.e38f68", "type": "telegram receiver", "z": "b4106ec1.63dd58", "name": "FMWatsonBot", "bot": "5f347711.7876d8", "saveDataDir": "", "x": 110, "y": 100, "wires": [ [ "f4b4ab25.5dde18", "f5d126df.5b6928" ], [] ] }, { "id": "c6ec445d.0840d8", "type": "telegram sender", "z": "b4106ec1.63dd58", "name": "Send2Telegram", "bot": "5f347711.7876d8", "x": 780, "y": 80, "wires": [ [] ] }, { "id": "f4b4ab25.5dde18", "type": "debug", "z": "b4106ec1.63dd58", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 290, "y": 60, "wires": [] }, { "id": "f5d126df.5b6928", "type": "function", "z": "b4106ec1.63dd58", "name": "Save chat context", "func": "msg.chatId = msg.payload.chatId;\nmsg.type = msg.payload.type;\nmsg.content = msg.payload.content;\nreturn msg;", "outputs": 1, "noerr": 0, "x": 230, "y": 160, "wires": [ [ "c3d1a92d.227568" ] ] }, { "id": "276cfad7.cef62e", "type": "function", "z": "b4106ec1.63dd58", "name": "Set Chat Context", "func": "msg.payload = {\n chatId : msg.chatId,\n topic : msg.type,\n type : \"message\",\n content : msg.payload};\nreturn msg;\n", "outputs": 1, "noerr": 0, "x": 730, "y": 220, "wires": [ [ "c6ec445d.0840d8" ] ] }, { "id": "c3d1a92d.227568", "type": "switch", "z": "b4106ec1.63dd58", "name": "Check msg type", "property": "type", "propertyType": "msg", "rules": [ { "t": "eq", "v": "message", "vt": "str" }, { "t": "eq", "v": "voice", "vt": "str" }, { "t": "else" } ], "checkall": "true", "repair": false, "outputs": 3, "x": 300, "y": 240, "wires": [ [ "e8452a44.f967c8" ], [ "6aea6224.578d8c" ], [] ] }, { "id": "e8452a44.f967c8", "type": "function", "z": "b4106ec1.63dd58", "name": "Echo message", "func": "msg.payload = {\n chatId : msg.chatId,\n topic : \"Text Echo\",\n type : msg.type,\n content : msg.content};\nreturn msg;", "outputs": 1, "noerr": 0, "x": 540, "y": 80, "wires": [ [ "c6ec445d.0840d8" ] ] }, { "id": "6aea6224.578d8c", "type": "change", "z": "b4106ec1.63dd58", "name": "Set voice URL", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "payload.weblink", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 440, "y": 300, "wires": [ [ "fc7b1590.557c" ] ] }, { "id": "493d1bac.216d3c", "type": "change", "z": "b4106ec1.63dd58", "name": "Set transcription", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "transcription", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 680, "y": 300, "wires": [ [ "276cfad7.cef62e" ] ] }, { "id": "fc7b1590.557c", "type": "watson-speech-to-text", "z": "b4106ec1.63dd58", "name": "S2T", "alternatives": 1, "speakerlabels": false, "smartformatting": false, "lang": "en-GB", "langhidden": "en-GB", "langcustom": "NoCustomisationSetting", "langcustomhidden": "", "custom-weight": "0.5", "band": "BroadbandModel", "bandhidden": "BroadbandModel", "keywords": "", "keywords-threshold": "0.5", "word-confidence": false, "password": "", "apikey": "#########CHANGED VALUE TO POST###########", "payload-response": false, "streaming-mode": false, "streaming-mute": true, "auto-connect": false, "discard-listening": false, "disable-precheck": false, "default-endpoint": true, "service-endpoint": "https://stream.watsonplatform.net/speech-to-text/api", "x": 530, "y": 360, "wires": [ [ "493d1bac.216d3c" ] ] }, { "id": "5f347711.7876d8", "type": "telegram bot", "z": "", "botname": "FMWatsonBot", "usernames": "", "chatids": "", "baseapiurl": "", "updatemode": "polling", "pollinterval": "300", "bothost": "", "localbotport": "8443", "publicbotport": "8443", "privatekey": "", "certificate": "", "verboselogging": false } ] Thanks in advance Ferruccio Flow images at https://i.ibb.co/Tv4nYyz/Telegram-Speech2-Text-Transcode-Error.jpg

windkh commented 5 years ago

I will take a look as soon as I can. Stay tuned...

windkh commented 5 years ago

Hi Ferruccio,

I tested your flow with the latest version and text as well as voice is recieved correctly.

The watson API key seems not to work: "Provided API key could not be found"

 

I can see that also the correct weblink is sent to that node:

https://api.telegram.org/file/bot171891934:AAHMlJbC19UQ8lGZ6-lnkSpztUe8RQgC90c/voice/file_45.oga

So at least everything is sent to the S2T node, but that error is displayed:

 

"{"context":{"requestId":"56160baa86524bdca6ab635c14b23bed","requestType":"incoming.Identity_Token","userAgent":"watson-developer-cloud-nodejs-3.16.1;","clientIp":"195.63.119.146","url":"https://iam.bluemix.net","instanceId":"iamid-7f4478d457-zvbgh","threadId":"159994","host":"iamid-7f4478d457-zvbgh","startTime":"23.01.2019 23:02:22:777 UTC","endTime":"23.01.2019 23:02:22:779 UTC","elapsedTime":"2","locale":"en_US","clusterName":"iam-id-prelon02-xij1"},"errorCode":"BXNIM0415E","errorMessage":"Provided API key could not be found"}"

 

Unfortunately I don't know how to proceed as I don't have an IBM account.

 

 

BTW: I would delete the "Set transcription" node and modify the existing "Set chat context" node like that:

msg.payload = {  chatId : msg.chatId,  topic : msg.type,  type : "message",  content : msg.transcription}; return msg;

 

regards KH

 

Gesendet: Mittwoch, 23. Januar 2019 um 14:09 Uhr Von: "Ferruccio Manclossi" notifications@github.com An: windkh/node-red-contrib-telegrambot node-red-contrib-telegrambot@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Betreff: [windkh/node-red-contrib-telegrambot] Flow perfectly works with telegram node v4.4.0, but fails with new version 5.1.5 (#63)

I've the following flow that works like a charm with v4.4.0 but stop working with 5.1.5 What is changed about "voice messages"? How can I fix it? [ { "id": "b4106ec1.63dd58", "type": "tab", "label": "Telegram", "disabled": false, "info": "" }, { "id": "d1198164.e38f68", "type": "telegram receiver", "z": "b4106ec1.63dd58", "name": "FMWatsonBot", "bot": "5f347711.7876d8", "saveDataDir": "", "x": 110, "y": 100, "wires": [ [ "f4b4ab25.5dde18", "f5d126df.5b6928" ], [] ] }, { "id": "c6ec445d.0840d8", "type": "telegram sender", "z": "b4106ec1.63dd58", "name": "Send2Telegram", "bot": "5f347711.7876d8", "x": 780, "y": 80, "wires": [ [] ] }, { "id": "f4b4ab25.5dde18", "type": "debug", "z": "b4106ec1.63dd58", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 290, "y": 60, "wires": [] }, { "id": "f5d126df.5b6928", "type": "function", "z": "b4106ec1.63dd58", "name": "Save chat context", "func": "msg.chatId = msg.payload.chatId;\nmsg.type = msg.payload.type;\nmsg.content = msg.payload.content;\nreturn msg;", "outputs": 1, "noerr": 0, "x": 230, "y": 160, "wires": [ [ "c3d1a92d.227568" ] ] }, { "id": "276cfad7.cef62e", "type": "function", "z": "b4106ec1.63dd58", "name": "Set Chat Context", "func": "msg.payload = {\n chatId : msg.chatId,\n topic : msg.type,\n type : \"message\",\n content : msg.payload};\nreturn msg;\n", "outputs": 1, "noerr": 0, "x": 730, "y": 220, "wires": [ [ "c6ec445d.0840d8" ] ] }, { "id": "c3d1a92d.227568", "type": "switch", "z": "b4106ec1.63dd58", "name": "Check msg type", "property": "type", "propertyType": "msg", "rules": [ { "t": "eq", "v": "message", "vt": "str" }, { "t": "eq", "v": "voice", "vt": "str" }, { "t": "else" } ], "checkall": "true", "repair": false, "outputs": 3, "x": 300, "y": 240, "wires": [ [ "e8452a44.f967c8" ], [ "6aea6224.578d8c" ], [] ] }, { "id": "e8452a44.f967c8", "type": "function", "z": "b4106ec1.63dd58", "name": "Echo message", "func": "msg.payload = {\n chatId : msg.chatId,\n topic : \"Text Echo\",\n type : msg.type,\n content : msg.content};\nreturn msg;", "outputs": 1, "noerr": 0, "x": 540, "y": 80, "wires": [ [ "c6ec445d.0840d8" ] ] }, { "id": "6aea6224.578d8c", "type": "change", "z": "b4106ec1.63dd58", "name": "Set voice URL", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "payload.weblink", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 440, "y": 300, "wires": [ [ "fc7b1590.557c" ] ] }, { "id": "493d1bac.216d3c", "type": "change", "z": "b4106ec1.63dd58", "name": "Set transcription", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "transcription", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 680, "y": 300, "wires": [ [ "276cfad7.cef62e" ] ] }, { "id": "fc7b1590.557c", "type": "watson-speech-to-text", "z": "b4106ec1.63dd58", "name": "S2T", "alternatives": 1, "speakerlabels": false, "smartformatting": false, "lang": "en-GB", "langhidden": "en-GB", "langcustom": "NoCustomisationSetting", "langcustomhidden": "", "custom-weight": "0.5", "band": "BroadbandModel", "bandhidden": "BroadbandModel", "keywords": "", "keywords-threshold": "0.5", "word-confidence": false, "password": "", "apikey": "#########CHANGED VALUE TO POST###########", "payload-response": false, "streaming-mode": false, "streaming-mute": true, "auto-connect": false, "discard-listening": false, "disable-precheck": false, "default-endpoint": true, "service-endpoint": "https://stream.watsonplatform.net/speech-to-text/api", "x": 530, "y": 360, "wires": [ [ "493d1bac.216d3c" ] ] }, { "id": "5f347711.7876d8", "type": "telegram bot", "z": "", "botname": "FMWatsonBot", "usernames": "", "chatids": "", "baseapiurl": "", "updatemode": "polling", "pollinterval": "300", "bothost": "", "localbotport": "8443", "publicbotport": "8443", "privatekey": "", "certificate": "", "verboselogging": false } ] Thanks in advance Ferruccio Flow images at https://i.ibb.co/Tv4nYyz/Telegram-Speech2-Text-Transcode-Error.jpg

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

windkh commented 5 years ago

Hi Ferruccio, 

the documentation of the speech to text node says:

 

Audio must be a WAV, FLAC or OGG encoded file.

 

I could see that a .oga file was sent from the telegram server.

Maybe the file format was changed by telegram?

 

At least I did not change anything in the telegrambot-nodes about handling voice messages.

regards KH

Gesendet: Mittwoch, 23. Januar 2019 um 14:09 Uhr Von: "Ferruccio Manclossi" notifications@github.com An: windkh/node-red-contrib-telegrambot node-red-contrib-telegrambot@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Betreff: [windkh/node-red-contrib-telegrambot] Flow perfectly works with telegram node v4.4.0, but fails with new version 5.1.5 (#63)

I've the following flow that works like a charm with v4.4.0 but stop working with 5.1.5 What is changed about "voice messages"? How can I fix it? [ { "id": "b4106ec1.63dd58", "type": "tab", "label": "Telegram", "disabled": false, "info": "" }, { "id": "d1198164.e38f68", "type": "telegram receiver", "z": "b4106ec1.63dd58", "name": "FMWatsonBot", "bot": "5f347711.7876d8", "saveDataDir": "", "x": 110, "y": 100, "wires": [ [ "f4b4ab25.5dde18", "f5d126df.5b6928" ], [] ] }, { "id": "c6ec445d.0840d8", "type": "telegram sender", "z": "b4106ec1.63dd58", "name": "Send2Telegram", "bot": "5f347711.7876d8", "x": 780, "y": 80, "wires": [ [] ] }, { "id": "f4b4ab25.5dde18", "type": "debug", "z": "b4106ec1.63dd58", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 290, "y": 60, "wires": [] }, { "id": "f5d126df.5b6928", "type": "function", "z": "b4106ec1.63dd58", "name": "Save chat context", "func": "msg.chatId = msg.payload.chatId;\nmsg.type = msg.payload.type;\nmsg.content = msg.payload.content;\nreturn msg;", "outputs": 1, "noerr": 0, "x": 230, "y": 160, "wires": [ [ "c3d1a92d.227568" ] ] }, { "id": "276cfad7.cef62e", "type": "function", "z": "b4106ec1.63dd58", "name": "Set Chat Context", "func": "msg.payload = {\n chatId : msg.chatId,\n topic : msg.type,\n type : \"message\",\n content : msg.payload};\nreturn msg;\n", "outputs": 1, "noerr": 0, "x": 730, "y": 220, "wires": [ [ "c6ec445d.0840d8" ] ] }, { "id": "c3d1a92d.227568", "type": "switch", "z": "b4106ec1.63dd58", "name": "Check msg type", "property": "type", "propertyType": "msg", "rules": [ { "t": "eq", "v": "message", "vt": "str" }, { "t": "eq", "v": "voice", "vt": "str" }, { "t": "else" } ], "checkall": "true", "repair": false, "outputs": 3, "x": 300, "y": 240, "wires": [ [ "e8452a44.f967c8" ], [ "6aea6224.578d8c" ], [] ] }, { "id": "e8452a44.f967c8", "type": "function", "z": "b4106ec1.63dd58", "name": "Echo message", "func": "msg.payload = {\n chatId : msg.chatId,\n topic : \"Text Echo\",\n type : msg.type,\n content : msg.content};\nreturn msg;", "outputs": 1, "noerr": 0, "x": 540, "y": 80, "wires": [ [ "c6ec445d.0840d8" ] ] }, { "id": "6aea6224.578d8c", "type": "change", "z": "b4106ec1.63dd58", "name": "Set voice URL", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "payload.weblink", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 440, "y": 300, "wires": [ [ "fc7b1590.557c" ] ] }, { "id": "493d1bac.216d3c", "type": "change", "z": "b4106ec1.63dd58", "name": "Set transcription", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "transcription", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 680, "y": 300, "wires": [ [ "276cfad7.cef62e" ] ] }, { "id": "fc7b1590.557c", "type": "watson-speech-to-text", "z": "b4106ec1.63dd58", "name": "S2T", "alternatives": 1, "speakerlabels": false, "smartformatting": false, "lang": "en-GB", "langhidden": "en-GB", "langcustom": "NoCustomisationSetting", "langcustomhidden": "", "custom-weight": "0.5", "band": "BroadbandModel", "bandhidden": "BroadbandModel", "keywords": "", "keywords-threshold": "0.5", "word-confidence": false, "password": "", "apikey": "#########CHANGED VALUE TO POST###########", "payload-response": false, "streaming-mode": false, "streaming-mute": true, "auto-connect": false, "discard-listening": false, "disable-precheck": false, "default-endpoint": true, "service-endpoint": "https://stream.watsonplatform.net/speech-to-text/api", "x": 530, "y": 360, "wires": [ [ "493d1bac.216d3c" ] ] }, { "id": "5f347711.7876d8", "type": "telegram bot", "z": "", "botname": "FMWatsonBot", "usernames": "", "chatids": "", "baseapiurl": "", "updatemode": "polling", "pollinterval": "300", "bothost": "", "localbotport": "8443", "publicbotport": "8443", "privatekey": "", "certificate": "", "verboselogging": false } ] Thanks in advance Ferruccio Flow images at https://i.ibb.co/Tv4nYyz/Telegram-Speech2-Text-Transcode-Error.jpg

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

fmanclossi commented 5 years ago

Hi, that was my first thoughts (telegram changes voice audio format), but the same flow perfectly works with telegram bot nodes v4.4.0 (on a node-red environment not updated) and fails on a node-red environment with telegram bot nodes v5.1.5 (both working with the same telegram bot and the same scenario (voice message). Did you change anything in how you collect voice message from 4.4.0 to 5.1.5?

Thanks in advance Ferruccio

windkh commented 5 years ago

I can‘t even remember when I changed something there the last time, but I will dig a little bit in the history .... Yesterday I created a bluemix account and installed the watson nodes, but I failed to get the correct credentials and apikey. So I got stuck in an authentication error. If you like to, we could find out this together in a websharing session as that problem really raised my interest.

fmanclossi commented 5 years ago

If you need help, I can assist you about IBM nodes ;) Did you installed node-red-node-watson nodes? They already use the new IAM authentication method based upon apikey. TIP: verify the URL associated to the S2T services that you created. If it is https://stream-fra.watsonplatform.net/speech-to-text/api you have to uncheck Default URL (or something similar) box on node config and select the right URL

windkh commented 5 years ago

... yes that could help. Right now I am busy, but maybe later let‘s say in 1-2 hours?

fmanclossi commented 5 years ago

today was a tough day... I need rest. What about tomorrow?

windkh commented 5 years ago

Sure

fmanclossi commented 5 years ago

You can contact me even tomorrow afternoon (GMT+1)

windkh commented 5 years ago

Hi Ferruccio,

I stepped through the S2T node and found out that the audio file is downloaded correctly from the server and stored in a TEMP directory

with the ending .audio. That file is analyzed and passed to the cloud as "opus" format. The cloud service fails to transcode it, resulting in that error you reported.

"unable to transcode data stream audio/opus -> audio/x-float-array"

 

I changed the audio.format variable in the code to "ogg" and then everything worked. From version 4.4.0 to 5.1.5 nothing changed regarding voice messages, neither

did I update the underlying api inbetween. This leads me to the conclusion that the file format is interpreted as OGG OPUS by the watson node.

Don't ask me why it fails to decode it.

 

I found out that there is a special handling for ogg files in ...node-red-node-watson\services\speech_to_text\v1.js Line 367

 

// If we get to here then the audio is in one of the supported formats.

if (audioData.format === 'ogg') {

audioData.format += ';codecs=opus';

}

 

In my eyes this is a bug as the opus codec is only added when audioData.format is "ogg", indeed it is resolved as "opus". See attachment.

I suggest to report this to the watson nodes author.

 

best regards KHW

 

 

Gesendet: Donnerstag, 24. Januar 2019 um 20:14 Uhr Von: "Ferruccio Manclossi" notifications@github.com An: windkh/node-red-contrib-telegrambot node-red-contrib-telegrambot@noreply.github.com Cc: "Karl-Heinz Wind" karl-heinz.wind@web.de, Comment comment@noreply.github.com Betreff: Re: [windkh/node-red-contrib-telegrambot] Flow perfectly works with telegram node v4.4.0, but fails with new version 5.1.5 (#63)

You can contact me even tomorrow afternoon (GMT+1)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

fmanclossi commented 5 years ago

Great! I forward your results to Watson team (on github, too) Thanks a lot

windkh commented 5 years ago

If you want to raise an issue in https://github.com/watson-developer-cloud/node-red-node-watson

then you can send him the audio file I attached. That one was created by telegram and downloaded by the watson node.

I added the extension .ogg to be able to play it using VLC. You can verify my findings by using a HEX editor.

best regards KHW

 

Gesendet: Donnerstag, 24. Januar 2019 um 20:14 Uhr Von: "Ferruccio Manclossi" notifications@github.com An: windkh/node-red-contrib-telegrambot node-red-contrib-telegrambot@noreply.github.com Cc: "Karl-Heinz Wind" karl-heinz.wind@web.de, Comment comment@noreply.github.com Betreff: Re: [windkh/node-red-contrib-telegrambot] Flow perfectly works with telegram node v4.4.0, but fails with new version 5.1.5 (#63)

You can contact me even tomorrow afternoon (GMT+1)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.