As said you will need to create a chat route with objects that tell what type of message to expect and how to handle the check and response and next chat_route to use on a correct answer.
So for example
{"looking_for": "yes", "type": "equals", "response":"I am, do you?", "next":1}
looking_for
would tell your flow that the chat_route element is now expecting a yes answer, the if conditional should use
type
which in this case is equals. So now the logic knows to look for yes
and check the values is equal to yes
. If type
was "include" and look_for
was user
, the logic would then check to see if your chat response ben
is in the array in msg.look_for.users
.
response
would be the response to a correct answer, probably the next question. next
tells the logic where to go for next chat_route.
(see edit example flow below)
You will need to set out your questions and answers and work a chat route you require and what checks and look_fors may be needed at each stage. You will also need to store your position in the chat route.
[edit] example of a flow no code, it will check different questions according to msg.chat_response.type
[{"id":"ca455474847ba3ce","type":"telegram receiver","z":"452103ea51141731","name":"","bot":"2199975104e81aee","saveDataDir":"","filterCommands":false,"x":150,"y":2700,"wires":[["08ae816037a35ee4"],[]]},{"id":"08ae816037a35ee4","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"chat_route","pt":"msg","to":"[{\"type\":\"contains\",\"look_for\":\"hi\",\"response\":\"I am, do you?\",\"next\":1},{\"type\":\"equals\",\"look_for\":\"yes\",\"response\":\"please enter\",\"next\":2},{\"type\":\"includes\",\"look_for\":\"users\",\"response\":\"welcome\",\"next\":0}]","tot":"json"},{"t":"set","p":"index","pt":"msg","to":"index","tot":"flow"},{"t":"set","p":"look_for.users","pt":"msg","to":"[\"ben\",\"tom\"]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":160,"y":2840,"wires":[["e0ae55fbcc572e87"]]},{"id":"e0ae55fbcc572e87","type":"switch","z":"452103ea51141731","name":"","property":"index","propertyType":"msg","rules":[{"t":"istype","v":"undefined","vt":"undefined"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":310,"y":2840,"wires":[["5d2087e81fb969dd"],["27e88685c06a2156"]]},{"id":"5d2087e81fb969dd","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"index","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":2820,"wires":[["27e88685c06a2156"]]},{"id":"27e88685c06a2156","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"chat_response","pt":"msg","to":"chat_route[msg.index]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":2860,"wires":[["73244018130c8899"]]},{"id":"73244018130c8899","type":"switch","z":"452103ea51141731","name":"","property":"chat_response.type","propertyType":"msg","rules":[{"t":"eq","v":"contains","vt":"str"},{"t":"eq","v":"equals","vt":"str"},{"t":"eq","v":"includes","vt":"str"}],"checkall":"false","repair":false,"outputs":3,"x":170,"y":2920,"wires":[["40a6011057d887c1"],["097e2fd202b1caa8"],["4fbea9d0c7f46442"]]},{"id":"40a6011057d887c1","type":"switch","z":"452103ea51141731","name":"","property":"payload.content","propertyType":"msg","rules":[{"t":"cont","v":"chat_response.look_for","vt":"msg"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":370,"y":2940,"wires":[["912b6e2b8f7e9c78"],["9e97ca28c26d95d7"]]},{"id":"097e2fd202b1caa8","type":"switch","z":"452103ea51141731","name":"","property":"payload.content","propertyType":"msg","rules":[{"t":"eq","v":"chat_response.look_for","vt":"msg"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":370,"y":3000,"wires":[["8b65270e871b1e11"],["9e97ca28c26d95d7"]]},{"id":"4fbea9d0c7f46442","type":"switch","z":"452103ea51141731","name":"","property":"look_for[msg.chat_response.look_for]","propertyType":"msg","rules":[{"t":"cont","v":"payload.content","vt":"msg"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":370,"y":3080,"wires":[["84836bd369f4fcd9"],["9e97ca28c26d95d7"]]},{"id":"912b6e2b8f7e9c78","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"payload.content","pt":"msg","to":"chat_response.response","tot":"msg"},{"t":"set","p":"index","pt":"flow","to":"chat_response.next","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":2940,"wires":[["f5fc85ba8acd22c7"]]},{"id":"9e97ca28c26d95d7","type":"switch","z":"452103ea51141731","name":"","property":"payload.content","propertyType":"msg","rules":[{"t":"eq","v":"resst","vt":"msg"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":510,"y":3140,"wires":[["3696f1206045b1a9"],["82cdf0ecc03a63e6"]]},{"id":"8b65270e871b1e11","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"payload.content","pt":"msg","to":"chat_response.response","tot":"msg"},{"t":"set","p":"index","pt":"flow","to":"chat_response.next","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":3000,"wires":[["f5fc85ba8acd22c7"]]},{"id":"84836bd369f4fcd9","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"payload.content","pt":"msg","to":"$$.chat_response.response & \" \" & $$.payload.content","tot":"jsonata"},{"t":"set","p":"index","pt":"flow","to":"chat_response.next","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":3060,"wires":[["f5fc85ba8acd22c7"]]},{"id":"f5fc85ba8acd22c7","type":"telegram sender","z":"452103ea51141731","name":"","bot":"2199975104e81aee","haserroroutput":false,"outputs":1,"x":810,"y":2880,"wires":[[]]},{"id":"82cdf0ecc03a63e6","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"payload.content","pt":"msg","to":"no programed response please answer question","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":3160,"wires":[["f5fc85ba8acd22c7"]]},{"id":"3696f1206045b1a9","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"payload.conyent","pt":"msg","to":"resetting","tot":"str"},{"t":"set","p":"index","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":3120,"wires":[["f5fc85ba8acd22c7"]]},{"id":"2199975104e81aee","type":"telegram bot","botname":"elcidtestbot","usernames":"","chatids":"-822824734","baseapiurl":"","updatemode":"polling","pollinterval":"300","usesocks":false,"sockshost":"","socksprotocol":"socks5","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","botpath":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]
1st must contain.
2nd must equal.
3rd must be in msg.look_for.users
array.