# How to use the RiveScript node from node-red-contrib-rive

**URL:** <https://discourse.nodered.org/t/how-to-use-the-rivescript-node-from-node-red-contrib-rive/30292>\
**Category:** General\
**Created:** [18 July 2020 13:10 UTC](https://discourse.nodered.org/t/how-to-use-the-rivescript-node-from-node-red-contrib-rive/30292 "2020-07-18T13:10:39Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [18 July 2020 13:10 UTC](https://discourse.nodered.org/t/how-to-use-the-rivescript-node-from-node-red-contrib-rive/30292/1 "2020-07-18T13:10:39Z")

</div>

I read about RiveScript for using with Telegram bots, which I can use instead of a large switch node.  
But I have not found, how to send the text from Telegram or any other node to the input of the RiveScript node.

I also used an inject node, but I can only see messages on the error output of the node.  
If I use an RiveScript with

```auto
+ *
- some text

```

I get the `some text` as reply, but nothing else. I tried to read the js of the node in `.node-red/node_modules/node-red-contrib-rive`, but got lost.

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [18 July 2020 14:28 UTC](https://discourse.nodered.org/t/how-to-use-the-rivescript-node-from-node-red-contrib-rive/30292/2 "2020-07-18T14:28:22Z")

</div>

What did you expect to get?  
as `some text` is the only answer you defined this is all the node will return.  
Isnt this what you would expect?

Johannes

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [18 July 2020 14:31 UTC](https://discourse.nodered.org/t/how-to-use-the-rivescript-node-from-node-red-contrib-rive/30292/3 "2020-07-18T14:31:30Z")

</div>

To me, the “first steps” at the official RiveScript tutorial was a great starting point back in the day: [https://www.rivescript.com/docs/tutorial](https://www.rivescript.com/docs/tutorial)

---

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [18 July 2020 14:36 UTC](https://discourse.nodered.org/t/how-to-use-the-rivescript-node-from-node-red-contrib-rive/30292/4 "2020-07-18T14:36:38Z")

</div>

Sorry, I had some other entries in the RiveScript file, but none of them worked.

Like this:

```auto
+ my name is *
- Hello, <star> 

+ hello bot
- hello back, guy!

```

So I wrote in Telegram `hello bot`, but got an error on the second output:

`ERR: No Reply Matched`

or after inserting `+ *` I got the text `some text`, which means, he didn't find a matching line.

---

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [18 July 2020 14:39 UTC](https://discourse.nodered.org/t/how-to-use-the-rivescript-node-from-node-red-contrib-rive/30292/5 "2020-07-18T14:39:38Z")

</div>

I read the tutorial, but my problem is how the input text is read by the RiveScript node. Where should I put it? in msg.payload, msg.payload.content (as Telegram uses this variable) or msg.xxxxx?

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [18 July 2020 15:00 UTC](https://discourse.nodered.org/t/how-to-use-the-rivescript-node-from-node-red-contrib-rive/30292/6 "2020-07-18T15:00:58Z")

</div>

In the rule, directly in `msg.payload` for all nodes, unless the node requests otherwise. If needed to move it for telegram, put a change node before or after the RiveScript node

The node you use could do with way better documentation. If you add a `msg.script` property, it will use that instead of the template. If `msg.context` exists it will use it as the RiveScript context (as object).  
It will then use `msg.payload` as input text:

> <https://github.com/technocreatives/node-red-contrib-rive/blob/0f2dfe498276d07380633331bf7863b64d2fbca9/rive/rive.js#L30>

---

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [18 July 2020 15:21 UTC](https://discourse.nodered.org/t/how-to-use-the-rivescript-node-from-node-red-contrib-rive/30292/7 "2020-07-18T15:21:57Z")

</div>

> [@afelix](#):
>
> If `msg.context` exists it will use it as the RiveScript context (as object).

Sorry, I do not understand, what content I should use in msg.context and what the RiveScript would do with that content!?

> [@afelix](#):
>
> The node you use could do with way better documentation.

indeed ☹

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [18 July 2020 15:21 UTC](https://discourse.nodered.org/t/how-to-use-the-rivescript-node-from-node-red-contrib-rive/30292/8 "2020-07-18T15:21:58Z")

</div>

Here is the change node I use before my rivescript node:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/2/c2ac9231530c45b7087cdcf37d95ec44171f6381.png)

And an example script:

```auto
! version = 2.0

! array cmds = on off

+ # (@cmds)
- |01,<star1>,<star2>

+ (@cmds) #
- |01,<star2>,<star1>

+ (@cmds)
- |02,Which switch/light would you like to turn <star1>? [1-10]

+ #
- |03,Would you like to turn switch/light <star1> on or off? [on|off]

+ *
- I'm sorry, I don't understand what you are asking for.\n
^ Please use the format: /light # on|off\n
^ You can even use: /on #

```

---

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [18 July 2020 15:35 UTC](https://discourse.nodered.org/t/how-to-use-the-rivescript-node-from-node-red-contrib-rive/30292/9 "2020-07-18T15:35:35Z")

</div>

Hi Julian,

I already saw your examples, but in my case it is a lot more simple.  
But I don't get a result, when injecting a string in msg.payload, which I have defined in a `+` line.  
As I understood Lena (@afelix), I have to fill some content in msg.context, when using msg.payload!?  
I think, I have to make small flow. Maybe there is some nasty little error, which drives me nuts.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [18 July 2020 15:46 UTC](https://discourse.nodered.org/t/how-to-use-the-rivescript-node-from-node-red-contrib-rive/30292/10 "2020-07-18T15:46:08Z")

</div>

Maybe you could share a test flow?

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [18 July 2020 15:56 UTC](https://discourse.nodered.org/t/how-to-use-the-rivescript-node-from-node-red-contrib-rive/30292/11 "2020-07-18T15:56:43Z")

</div>

> [@stefan24](#):
>
> As I understood Lena (@afelix), I have to fill some content in msg.context, when using msg.payload!?

No you don’t, it’s optional, and it’s for if you want to use RiveScript’s context processing on messages, as explained in the link for RiveScript before

---

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [18 July 2020 19:48 UTC](https://discourse.nodered.org/t/how-to-use-the-rivescript-node-from-node-red-contrib-rive/30292/12 "2020-07-18T19:48:44Z")

</div>

> [@afelix](#):
>
> it’s for if you want to use RiveScript’s context processing on messages, as explained in the link for RiveScript before

In [Tutorial - RiveScript.com](https://www.rivescript.com/docs/tutorial) I have not found any "context". And the js code was not clear to me. Nevermind, I don't think, I will need the context.  
I will post my test flow in a few minutes.

---

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [18 July 2020 20:12 UTC](https://discourse.nodered.org/t/how-to-use-the-rivescript-node-from-node-red-contrib-rive/30292/13 "2020-07-18T20:12:51Z")

</div>

I found my error, when building a test flow:

I always used a "!" at the end of the + line.

`+ hello bot!`

then the line will NOT be found.

The RiveScript tutorial states:

> **Important Note:** a trigger is ALWAYS lower cased, and it doesn't contain punctuation symbols.

The examples above were correct, but I didn't use these. Sorry!!

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [19 July 2020 11:58 UTC](https://discourse.nodered.org/t/how-to-use-the-rivescript-node-from-node-red-contrib-rive/30292/14 "2020-07-19T11:58:15Z")

</div>

I just took a look again, and I understand your confusion. This node is inspired by a set of chat nodes that invent their own whole context idea, if you’re familiar with that set it makes a bit more sense but simply said this node needs way better documentation.

The context is actually mentioned in the rivescript docs but has a different name there. It’s what they refer to as user variables near the very end. If you were to set `msg.context.user`, it’s usuable in your script as `<id>`, but if unset defaults to `localhost` like the rivescript docs describe. `msg.context.vars` is an object too, containing the set of user variables for this user, that you can use with `<get>` and `<set>` in your script.

---

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [19 July 2020 12:19 UTC](https://discourse.nodered.org/t/how-to-use-the-rivescript-node-from-node-red-contrib-rive/30292/15 "2020-07-19T12:19:06Z")

</div>

Ah, ok. It seems as if could use these variables some day. Thanks for the clarification!

---

<div class="post-metadata">

**Author:** ![martynwheeler](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/martynwheeler/32/24731_2.png) [@martynwheeler](https://discourse.nodered.org/u/martynwheeler)\
**Post date:** [22 July 2020 08:50 UTC](https://discourse.nodered.org/t/how-to-use-the-rivescript-node-from-node-red-contrib-rive/30292/16 "2020-07-22T08:50:28Z")

</div>

Hi,  
sorry to break into this thread. I am rather confused with the rivescript node too. I am trying a simple test:  
! version = 2.0

- hello bot

- Hello, human!

with the input coming from a telegram receiver node. It contains:

{"chatId":\*\*\*\*\*\*\*\*\*\*\*,"messageId":23,"type":"message","content":"hello bot"}

but I get ERR: No Reply Matched? I suspect that I need a change node but I cannot figure out what it needs to be changed to? I agree the documentation is somewhat sparse.

Martyn

---

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [22 July 2020 09:26 UTC](https://discourse.nodered.org/t/how-to-use-the-rivescript-node-from-node-red-contrib-rive/30292/17 "2020-07-22T09:26:23Z")

</div>

Telegram Receiver uses msg.payload.content. You may have to move the "hello chat" to msg.payload with a change node.  
 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/5/c503e3e56189d6b8ca2f3638e2e9fd31a50e0a8d.png)

---

<div class="post-metadata">

**Author:** ![martynwheeler](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/martynwheeler/32/24731_2.png) [@martynwheeler](https://discourse.nodered.org/u/martynwheeler)\
**Post date:** [22 July 2020 13:43 UTC](https://discourse.nodered.org/t/how-to-use-the-rivescript-node-from-node-red-contrib-rive/30292/18 "2020-07-22T13:43:22Z")

</div>

gotcha, thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [5 August 2020 13:43 UTC](https://discourse.nodered.org/t/how-to-use-the-rivescript-node-from-node-red-contrib-rive/30292/19 "2020-08-05T13:43:27Z")

</div>

Closed on 5 August 2020 13:43 UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
