Skip to content
This repository was archived by the owner on Mar 13, 2024. It is now read-only.

Commit cb9aa3f

Browse files
committed
Publishing version 1.0 of Dialog
0 parents  commit cb9aa3f

File tree

1,015 files changed

+11369
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,015 files changed

+11369
-0
lines changed

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# IntelliJ project files
2+
.idea
3+
!.idea/inspectionProfiles/*
4+
!.idea/codeStyles/*
5+
!.idea/kotlinc.xml
6+
.gradle
7+
out
8+
local.properties
9+
build
10+
11+
# Eclipse project files
12+
.classpath
13+
.settings
14+
.project
15+
*.iml

.travis.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
language: java
2+
3+
notifications:
4+
email: false
5+
6+
script:
7+
- ./gradlew test build
8+
9+
before_cache:
10+
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
11+
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
12+
13+
cache:
14+
directories:
15+
- $HOME/.gradle/caches/
16+
- $HOME/.gradle/wrapper/
17+
18+
jdk:
19+
- oraclejdk8
20+
21+
after_success:
22+
- bash <(curl -s https://codecov.io/bash)

LICENSE

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
The MIT license (MIT)
2+
3+
Copyright (c) 2018 REWE Digital GmbH
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
7+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
8+
persons to whom the Software is furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
11+
Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MAINTAINERS

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Volkmar Vogel <[email protected]>
2+
René Kilczan <[email protected]>

PULL_REQUEST_TEMPLATE.md

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
## Pull Request Template
2+
3+
Please use this to create a roadmap for your project or to track bugs. A pull request template improves development quality and provides a common guideline for contributors to follow. It also enables to you to reference issues and shows others your development progress.
4+
5+
<!--- Provide a general summary of your changes in the Title above -->
6+
7+
### Description
8+
<!--- Describe your changes in detail -->
9+
10+
### Related Issue
11+
<!--- This project only accepts pull requests related to open issues -->
12+
<!--- If suggesting a new feature or change, please discuss it in an issue first -->
13+
<!--- If fixing a bug, there should be an issue describing it with steps to reproduce -->
14+
<!--- Please link to the issue here: -->
15+
<!--- You can reference to an issue or pr with the #<number> -->
16+
17+
### Motivation and Context
18+
<!--- Why is this change required? What problem does it solve? -->
19+
20+
### How Has This Been Tested?
21+
<!--- Please describe in detail how you tested your changes. -->
22+
<!--- Include details of your testing environment, and the tests you ran to -->
23+
<!--- see how your change affects other areas of the code, etc. -->
24+
<!--- If you already have CI configured you can remove this part -->
25+
26+
### Screenshots (if appropriate):
27+
28+
### Types of changes
29+
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
30+
- [ ] Bug fix (non-breaking change which fixes an issue)
31+
- [ ] New feature (non-breaking change which adds functionality)
32+
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
33+
34+
### Checklist:
35+
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
36+
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
37+
- [ ] My code follows the code style of this project.
38+
- [ ] My change requires a change to the documentation.
39+
- [ ] I have updated the documentation accordingly.
40+
- [ ] I have read the **CONTRIBUTING** document.
41+
- [ ] I have added tests to cover my changes.
42+
- [ ] All new and existing tests passed.
43+
<!--- Provide a general summary of your changes in the Title above -->

README.md

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# Dialog [![Build Status][travis-image]][travis-url] [![Code Coverage][codecov-img]][codecov-url] [![License: MIT][mit-image]][mit-url] [![Stars][star-img]][star-url]
2+
3+
Dialog is a Dialogflow v2 API implementation written in Kotlin. With some great optional extensions you can use to
4+
write your own voice application fast.
5+
6+
## Top features
7+
8+
- Dialogflow V2 API reference implementation written in Kotlin
9+
- Interceper API for adding e.g. tracking
10+
- Spring reference implementation
11+
- SSML builder for creating rich responses
12+
- Plugin for Konversation to distinct the dialogs from code
13+
14+
### Dialogflow API v2 Usage
15+
16+
A response with a simple response and a basic card would look like this:
17+
18+
return handler.responseBuilder
19+
.expectUserResponse(true)
20+
.withGoogleSimpleResponse(speech)
21+
.withGoogleBasicCard(
22+
title = "CardTitle",
23+
subtitle = "CardSubTitle",
24+
formattedText = "CardFormattedText",
25+
buttons = mutableListOf(
26+
GoogleButton(
27+
title = "ButtonText",
28+
openUrlAction = OpenUrlAction(url = "https://rewe-digital.com/")
29+
)
30+
)
31+
)
32+
.withGoogleSimpleResponse(question)
33+
.withGoogleSuggestions(*suggestions.orEmpty())
34+
35+
<sup>Example taken from [UiElementsIntentHandler](spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/UiElementsIntentHandler.kt#L40-L54)</sub>
36+
37+
Here is a list of some selected methods you can use to create the response of your voice application:
38+
- [`askGoogleForCoarseLocation(...)`](docs/core/org.rewedigital.dialog.handler/-dialogflow-response-builder/ask-google-for-coarse-location.md)
39+
- [`askGoogleForLocation(...)`](docs/core/org.rewedigital.dialog.handler/-dialogflow-response-builder/ask-google-for-location.md)
40+
- [`askGoogleForPreciseLocation(...)`](docs/core/org.rewedigital.dialog.handler/-dialogflow-response-builder/ask-google-for-precise-location.md)
41+
- [`askGoogleForSignIn(...)`](docs/core/org.rewedigital.dialog.handler/-dialogflow-response-builder/ask-google-for-sign-in.md)
42+
- [`expectUserResponse(...)`](docs/core/org.rewedigital.dialog.handler/-dialogflow-response-builder/expect-user-response.md)
43+
- [`withCard(...)`](docs/core/org.rewedigital.dialog.handler/-dialogflow-response-builder/with-card.md)
44+
- [`withGoogleBasicCard(...)`](docs/core/org.rewedigital.dialog.handler/-dialogflow-response-builder/with-google-basic-card.md)
45+
- [`withGoogleCarouselSelect(...)`](docs/core/org.rewedigital.dialog.handler/-dialogflow-response-builder/with-google-carousel-select.md)
46+
- [`withGoogleLinkOutSuggestion(...)`](docs/core/org.rewedigital.dialog.handler/-dialogflow-response-builder/with-google-link-out-suggestion.md)
47+
- [`withGoogleListSelect(...)`](docs/core/org.rewedigital.dialog.handler/-dialogflow-response-builder/with-google-list-select.md)
48+
- [`withGoogleReprompts(...)`](docs/core/org.rewedigital.dialog.handler/-dialogflow-response-builder/with-google-reprompts.md)
49+
- [`withGoogleSimpleResponse(...)`](docs/core/org.rewedigital.dialog.handler/-dialogflow-response-builder/with-google-simple-response.md)
50+
- [`withGoogleSimpleResponses(...)`](docs/core/org.rewedigital.dialog.handler/-dialogflow-response-builder/with-google-simple-responses.md)
51+
- [`withGoogleSuggestions(...)`](docs/core/org.rewedigital.dialog.handler/-dialogflow-response-builder/with-google-suggestions.md)
52+
- [`withImage(...)`](docs/core/org.rewedigital.dialog.handler/-dialogflow-response-builder/with-image.md)
53+
- [`withQuickReplies(...)`](docs/core/org.rewedigital.dialog.handler/-dialogflow-response-builder/with-quick-replies.md)
54+
- [`withText(...)`](docs/core/org.rewedigital.dialog.handler/-dialogflow-response-builder/with-text.md)
55+
56+
## Dialog Intro
57+
58+
You can use the core library for you own implementation, where you can choose your own application server or your own
59+
server less hosting. In the end you need to setup your rest endpoints yourself and manage the conversion of the POKOs
60+
(plain old Kotlin objects).
61+
62+
When you have your request converted to [WebhookRequest] Dialog can handle the request by using the [RequestResolver].
63+
The constructor expects 4 arguments: `intentHandlers`, `requestInterceptors`, `responseInterceptors` and
64+
`fallbackAction`. The first three options are lists each of them are explained in more details in the following sections.
65+
66+
### Handling intents
67+
68+
The [DialogflowIntentHandler] is the core where you handle the intents. Each handler can choose independent if it feels
69+
responsible for the intent. This is very helpful if you have some intents which depends on the current context.
70+
71+
[RequestResolver] will call the function [`canHandleDialogflowIntent(...)`][intent-methods]. When your intent feels
72+
responsible return `true` then the [`handleDialogflowIntent(...)`][intent-methods] will be called. Please note that
73+
you define the order of the calls with the order of of the `RequestResolver`'s `intentHandlers`. First come first serve,
74+
you should avoid that multiple handlers return `true` of the same intent, based your the list implementation the result
75+
could be random.
76+
77+
As said above the [RequestResolver] will call the [`handleDialogflowIntent(...)`][intent-methods] method if you return
78+
`true` in the [`canHandleDialogflowIntent`][intent-methods] method. The logic for handling the Intent goes here. To
79+
create a response use [`input.responseBuilder`][ResponseBuilder].
80+
81+
### Interceptors
82+
83+
You can use the [RequestInterceptor] for tracking. In `onDialogflowRequest()` will get the input where you can grep the
84+
data you need for analytics.
85+
86+
### FallbackAction
87+
88+
This is a special [DialogflowIntentHandler] which will be invoked when no intent handler will feel responsible for your
89+
request. Please note that the result of the `canHandle` method will be ignored for the fallback usage.
90+
91+
### Example
92+
93+
class WelcomeIntentHandler : DialogflowIntentHandler {
94+
95+
override fun canHandleDialogflowIntent(handler: DialogflowHandler): Boolean {
96+
return handler.action?.equals("input.welcome") ?: false
97+
}
98+
99+
override fun handleDialogflowIntent(handler: DialogflowHandler): DialogflowResponseBuilder {
100+
return handler.responseBuilder.withText("Welcome to Dialog!")
101+
}
102+
}
103+
104+
105+
## Using Dialog with Spring
106+
107+
We have a special plugin for Spring which should make it very easy to implement your own webservice with it. You can use
108+
the spring-sample project as template for your own project. When you use our plugin you should annotate each intent with
109+
`@IntentHandler` to make that intent handler to a component which provides you all the advantages of dependency
110+
injection. The best it that we use it also for discovering your intent handler automatically. For the fallback intent
111+
you should use the annotation `@FallbackIntentHandler`, if it is missing you service won't start up.
112+
113+
## License
114+
115+
The MIT license (MIT)
116+
117+
Copyright (c) 2018 REWE Digital GmbH
118+
119+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
120+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
121+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
122+
persons to whom the Software is furnished to do so, subject to the following conditions:
123+
124+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
125+
Software.
126+
127+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
128+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
129+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
130+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
131+
132+
[travis-image]: https://travis-ci.org/rewe-digital-incubator/dialog.svg?branch=master
133+
[travis-url]: https://travis-ci.org/rewe-digital-incubator/dialog
134+
[codecov-img]: http://codecov.io/github/rewe-digital-incubator/dialog/coverage.svg?branch=master
135+
[codecov-url]: http://codecov.io/github/rewe-digital-incubator/dialog?branch=master
136+
[mit-image]: https://img.shields.io/badge/License-MIT-yellow.svg
137+
[mit-url]: https://opensource.org/licenses/MIT
138+
[star-img]: https://img.shields.io/github/stars/rewe-digital-incubator/dialog.svg?style=social&label=Star&maxAge=3600
139+
[star-url]: https://github.com/rewe-digital-incubator/dialog/stargazers
140+
[WebhookRequest]: core/src/main/kotlin/org/rewedigital/dialog/model/dialogflow/WebhookRequest.kt
141+
[RequestResolver]: docs/core/org.rewedigital.dialog.resolver/-request-resolver/index.md
142+
[DialogflowIntentHandler]: docs/core/org.rewedigital.dialog.handler/-dialogflow-intent-handler/index.md
143+
[intent-methods]: docs/core/org.rewedigital.dialog.handler/-dialogflow-intent-handler/index.md#Functions
144+
[ResponseBuilder]: docs/core/org.rewedigital.dialog.handler/-dialogflow-response-builder/index.md
145+
[RequestInterceptor]: docs/core/org.rewedigital.dialog.interceptors/-request-interceptor/index.md

build.gradle

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
apply plugin: 'kotlin'
2+
apply plugin: 'com.github.ben-manes.versions'
3+
4+
ext {
5+
dokka_version = '0.9.17'
6+
versions = [:]
7+
versions.kotlin = '1.3.11'
8+
versions.core = '1.0'
9+
versions.ssml = '1.0'
10+
versions.ssml_plugin = '1.0'
11+
versions.spring_plugin = '1.0'
12+
versions.konversation_plugin = '1.0'
13+
}
14+
15+
buildscript {
16+
ext.kotlin_version = '1.3.20'
17+
ext.dokka_version = '0.9.17'
18+
19+
repositories {
20+
mavenLocal()
21+
jcenter()
22+
}
23+
dependencies {
24+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
25+
classpath 'com.github.ben-manes:gradle-versions-plugin:0.20.0'
26+
classpath "org.jetbrains.dokka:dokka-gradle-plugin:${dokka_version}"
27+
}
28+
}
29+
30+
allprojects {
31+
repositories {
32+
mavenLocal()
33+
jcenter()
34+
maven { url 'https://jitpack.io' }
35+
}
36+
}

core/build.gradle

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
group 'org.rewedigital.voice'
2+
version rootProject.ext.versions.core
3+
4+
apply plugin: 'kotlin'
5+
apply plugin: 'maven-publish'
6+
apply from: '../docu.gradle'
7+
8+
dependencies {
9+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
10+
}
11+
12+
publishing.publications {
13+
maven(MavenPublication) {
14+
artifactId = 'dialog'
15+
from components.java
16+
}
17+
}
18+
19+
task sourcesJar(type: Jar, dependsOn: classes) {
20+
archiveClassifier = 'sources'
21+
from sourceSets.main.allSource
22+
}
23+
24+
task javadocJar(type: Jar, dependsOn: javadoc) {
25+
archiveClassifier = 'javadoc'
26+
from sourceSets.main.allSource
27+
}
28+
29+
artifacts {
30+
archives sourcesJar
31+
archives javadocJar
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package org.rewedigital.dialog.extensions
2+
3+
4+
internal fun <T> MutableList<T>?.orEmpty() = this ?: mutableListOf()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.rewedigital.dialog.extensions
2+
3+
4+
private val ssmlRegex = "^(?i)<speak\\b[^>]*>(.*?)</speak>$".toRegex()
5+
6+
internal fun String.isSsml() = ssmlRegex.containsMatchIn(this)

0 commit comments

Comments
 (0)