Support
Quality
Security
License
Reuse
kandi has reviewed rivescript-java and discovered the below as its top functions. This is intended to give you an instant insight into rivescript-java implemented functionality, and help decide if they suit your requirements.
A RiveScript interpreter for Java. RiveScript is a scripting language for chatterbots.
About RiveScript
+ hello bot
- Hello human.
Installation
<dependency>
<groupId>com.rivescript</groupId>
<artifactId>rivescript-core</artifactId>
<version>0.10.0</version>
</dependency>
Usage
import com.rivescript.Config;
import com.rivescript.RiveScript;
// Create a new bot with the default settings.
RiveScript bot = new RiveScript();
// To enable UTF-8 mode, you'd have initialized the bot like:
RiveScript bot = new RiveScript(Config.utf8());
// Load a directory full of RiveScript documents (.rive files)
bot.loadDirectory("./replies");
// Load an individual file.
bot.LoadFile("./testsuite.rive");
// Sort the replies after loading them!
bot.sortReplies();
// Get a reply.
String reply = bot.reply("user", "Hello bot!");
Configuration
RiveScript bot = new RiveScript(Config.newBuilder()
.throwExceptions(false) // Whether exception throwing is enabled
.strict(true) // Whether strict syntax checking is enabled
.utf8(false) // Whether UTF-8 mode is enabled
.unicodePunctuation("[.,!?;:]") // The unicode punctuation pattern
.forceCase(false) // Whether forcing triggers to lowercase is enabled
.concat(ConcatMode.NONE) // The concat mode
.depth(50) // The recursion depth limit
.sessionManager(sessionManager) // The session manager for user variables
.errorMessages(errors) // Map of custom error messages
.build());
UTF-8 Support
// Make a new bot with UTF-8 mode enabled and override the punctuation
characters that get stripped from the user's message.
RiveScript bot = new RiveScript(Config.Builder
.utf8()
.unicodePunctuation("[.,!?;:]")
.build());
Spring Boot Starter
<dependency>
<groupId>com.rivescript</groupId>
<artifactId>rivescript-spring-boot-starter</artifactId>
<version>0.10.0</version>
</dependency>
Building
./gradlew build
Samples
/quit - Quit the program
/dump topics - Dump the internal topic/trigger/reply struct (debugging)
/dump sorted - Dump the internal trigger sort buffers (debugging)
/last - Print the last trigger you matched.
License
The MIT License (MIT)
Copyright (c) 2016 the original author or authors.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
QUESTION
react-native-gifted-chat How to send on pressing return
Asked 2022-Feb-21 at 11:33How do I make the return button on the mobile keyboard send the message instead of creating a new line? I tried using onSubmitEditing
in the textInputProps
but couldn't get it to work.
ANSWER
Answered 2022-Feb-21 at 11:33You need to implement your own ChatComposer
and pass the onSubmitEditing
prop in the textInputProps
in there. In order to prevent keyboard dismiss you also need to set blurOnSubmit
to false.
const [messages, setMessages] = useState([])
const onSend = useCallback((messages = []) => {
setMessages((previousMessages) => GiftedChat.append(previousMessages, messages))
}, [])
const ChatComposer = (
props: ComposerProps & {
onSend: SendProps<IMessage>["onSend"]
text: SendProps<IMessage>["text"]
}
) => {
return (
<Composer
{...props}
textInputProps={{
...props.textInputProps,
blurOnSubmit: false,
multiline: false,
onSubmitEditing: () => {
if (props.text && props.onSend) {
props.onSend({ text: props.text.trim() }, true)
}
},
}}
/>
)
}
return (
<GiftedChat messages={messages} onSend={onSend} renderComposer={ChatComposer} />
)
If you want to remove the default send
button from the text input field on the right, you need to pass a custom renderSend
button, which could be empty, e.g.
renderSend={() => {}}
Notice, that I have tested all of the above on iOS only. Android might behave differently.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Save this library and start creating your kit