node-red-contrib-chatbot icon indicating copy to clipboard operation
node-red-contrib-chatbot copied to clipboard

New node (http request) with a possibility to receive webhook. Is it possible to?

Open german-st opened this issue 7 years ago • 11 comments

Hello.

We often use third-party api to create chat-bots using Node-RED. We encounter the situation when, after sending a request, we need to receive not only the response of the service, but also that it will send the service to the webhook specified by us. For example. We send a message to the user using the http request node. After that, the user can respond to the bot and in this case a message will come to our webhook. But since we only get an answer that we have successfully called a service and can not get what comes to webhook in the same node, we can not continue the full chain (flow). Thus, all calls to our web-based hook can be obtained only in another node http in. And our flow is interrupted.

Is it possible to implement a new node that can, in addition to calling the service, also wait for receiving a message on the web-hook and give in addition to the reply also the message received by Webhook ?

A similar implementation already exists in telegram nodes for interaction with telegrams, for example. But since you need to use a third party, you need a new node. Which can be a universal tool for the case when you need to call API and get more data that will come to webhook. I think a lot where it might be needed.

How do I imagine the implementation. The flow starts with the node http in which the data is received (our webhook), then we have a flow with some logic and there comes a time when we need to call api and in the same node get in addition a reply message that will come to webhook. In this case, if the node specifies that we need to get data from the webhook in addition to the service, then the first node does not receive a message so that the chain can continue.

As now it is possible to realize for example connectors to telegrams(very convenient): 34919646-8463ef22-f978-11e7-8852-74b41231a859

How to see the implementation of a new node: 34919765-6eb9e022-f979-11e7-8f7a-4308721e7508

In fact, this is the implementation of the flag in the http request node and http in node. I would gladly have tried to implement it myself, but unfortunately I'm still very new to the Node.js

Tell me please, is it possible to implement this and will it be in your plans? Or maybe there is still some way to solve this case? Thank you so much and sorry for my bad english.

german-st avatar Jan 15 '18 10:01 german-st

I'm not sure I've understood perfectly, the problem is that at the end of the second http node (where is the red arrow) you need some information that are available at the end of the first output node, right? And you need a way to carry on this value to the second http node?

If this is the case you don't need an extra node, each node takes the message from the input and stores the result in message.payload, leaving the rest untouched. So you can store any information at the beginning of your node, for example with a Function node,

msg.myVariable = 42;

and NodeRED will keep this value until the end of the flow.

guidone avatar Jan 15 '18 16:01 guidone

@guidone Hello Unfortunately no. About this I know and actively use. I need the second node after the call of the web service, I was waiting there for receiving the message on the webhook specified by us and gave it also. In general, for nodes to work in the same way that nodes http in and http request worked as telegram receiver and telegram sender. In effect, make the track flag in the http request node. And so that when this flag is true then the first node(http in) ignores the message. The message should come in the second.

The first node specifies my service, which receives messages from the user. The second node allows me to call a third party API to send a message to the user. And in it I want to receive the user's answers (calling our webhook service) to continue the flow.I hope everything is explained correctly)

I really hope for your answer. Thanks.

german-st avatar Jan 16 '18 16:01 german-st

@guidone Any ideas? Or I have not explained it clearly)

german-st avatar Jan 18 '18 11:01 german-st

Hi @GermaN-st now I understand, sorry for the late answer. I think that this node would be out of the scope of RedBot, have you tried the Node-Red group on Slack (node-red.slack.com)? Perhaps someone has the same problem

guidone avatar Jan 23 '18 13:01 guidone

Hello, @guidone Yes, I created an issue. Also advised to contact Slask group. I just thought that for the functionality of the RedBot it would be very useful that. Since in fact we will be able to use any messenger via the API. Of course, the scripts would become larger and more functions with the code, but it would be possible to use any messenger having api.

I realized that to use any api, there are two things:

  1. context
  2. http request node with the ability to catch the answer in it the same

It seems to me that this is a universal tool. Maybe I'm wrong) What do you say?

german-st avatar Jan 23 '18 13:01 german-st

Hi @german-st I've a final beta for the global configuration, would you like to test it before the release?

npm install node-red-contrib-chatbot@globalconfiguration

Thanks

guidone avatar Mar 29 '18 07:03 guidone

Hello @guidone I am tested and it works fine ;) Checked in two configurations.

telegram: { 'Knowledge': { token: 'test:test', polling: 1000, parseMode: 'html', } }, facebook: { 'KnowledgeBOT': { token: 'test', appSecret: '77777', verifyToken: '777777' } },

Everything works fine. Unfortunately there is no way to check the slack and the smooch. But I think they also work. I'm waiting for the release now.

Please add some examples of the configurations to the description. I had to look to the code for correct field names)))

Thank you very much.

german-st avatar Mar 30 '18 09:03 german-st

@german-st added some docs, do you think it's enough? Something missing?

guidone avatar Mar 31 '18 09:03 guidone

@guidone All is well. I do not know, maybe we should add Smooch example?

german-st avatar Apr 01 '18 19:04 german-st

@german-st the smooch connector is still old style and doesn't support global configuration, still wondering if someone is using it

guidone avatar Apr 05 '18 15:04 guidone

@guidone I just noticed that it is there, and there is no description for the configuration. So I wrote it) I do not use it myself. Then there is nothing more to add)

german-st avatar Apr 05 '18 16:04 german-st