Skip to content

Commit

Permalink
API.AI now Dialogflow
Browse files Browse the repository at this point in the history
* apai.ai is now dialogflow

* introduce dialogflow

* base examples

* cros headers

* instalation procedures and tests

* travis ci

* repo updates

* dialogflow version update

* tests path

* package version and build status

* update setup classifier

* summary update
  • Loading branch information
vkosuri authored Oct 15, 2017
1 parent b91296f commit 3228402
Show file tree
Hide file tree
Showing 37 changed files with 348 additions and 365 deletions.
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
language: python

python:
- '2.7'
- '3.4'
- '3.5'

install:
- pip install coveralls
- pip install -r requirements.txt

script:
- python django_dialogflow/manage.py test django_dialogflow.tests

after_success:
- coveralls
59 changes: 46 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
# django-apiai
# Django Dialogflow

Django [API.AI](https://api.ai/) is a web client to chat.
[![Package Version](https://img.shields.io/pypi/v/django-dialogflow.svg)](https://pypi.python.org/pypi/django-dialogflow/)
[![Build Status](https://travis-ci.org/vkosuri/django-dialogflow.svg?branch=master)](https://travis-ci.org/vkosuri/django-dialogflow)

## How to train
In progress
Django [Dialogflow](https://dialogflow.com) is a web client to chat.

## Development
To make development environment clone this repository
## Using the development version

git clone https://github.com/vkosuri/django-apiai.git
You can clone the git repository by doing the following:

``` Bash
virtualenv venv
source venv/bin/activate
pip install --upgrade pip
pip install --upgrade -r requirements.txt
$ git clone git://github.com/vkosuri/django-dialogflow.git
```

## Production your Bot
Expand Down Expand Up @@ -47,10 +43,47 @@ CORS_ORIGIN_WHITELIST = (
)
```

## Installation

If you are trying ``django_dialogflow`` as app,

Then you could install django-dialogflow either via the Python Package Index (PyPI) or from source.

To install using pip :

``` Bash
$ pip install django-dialogflow
```

and then add it to your installed apps:

``` Bash
INSTALLED_APPS = (
...
'django_dialogflow',
...
)
```

You will then want to create the necessary tables. If you generating schema migrations, you'll want to run:

``` Bash
$ python manage.py migrate django_dialogflow
```

## Examples
All examples are located here https://github.com/vkosuri/django-apiai/tree/master/examples

All [examples](./examples) are located here Github repo

## Motivation

https://github.com/gunthercox/django_chatterbot

## LICENSE
Licensed under MIT https://github.com/vkosuri/django-apiai/blob/master/LICENSE.md
Licensed under [MIT](./LICENSE.md)

## Contributing

Development of django_dialogflow happens at Github: http://github.com/vkosuri/django-dialogflow

You are highly encouraged to participate in the development. If you don't like Github (for some reason) you're welcome to send regular patches.
7 changes: 7 additions & 0 deletions django_dialogflow/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
Django Dialogflow chat agent
"""
__version__ = '0.0.1'
__author__ = 'Mallikarjunarao Kosuri'
__email__ = 'malli.kv2@gmail.com'
__url__ = 'https://github.com/vkosuri/django-dialogflow'
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions django_dialogflow/django_dialogflow/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.apps import AppConfig


class DjangoDialogflowConfig(AppConfig):

name = 'django_dialogflow'
label = 'django_dialogflow'
verbose_name = 'Django Dialogflow'
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-09-25 12:20
# Generated by Django 1.11.5 on 2017-10-15 02:23
from __future__ import unicode_literals

from django.db import migrations, models
Expand Down Expand Up @@ -28,12 +28,11 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('text', models.CharField(max_length=400)),
('pub_date', models.DateTimeField(verbose_name='date published')),
],
),
migrations.AddField(
model_name='response',
name='statement',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='chat.Statement'),
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='django_dialogflow.Statement'),
),
]
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Django settings for apiai_chat project.
Django settings for django_dialogflow project.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/
Expand All @@ -22,17 +22,13 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['localhost']

# API.AI Settings
URL = 'https://api.api.ai/v1/query'
# Dialogflow settings

# demo agent access token: e5dc21cab6df451c866bf5efacb40178
CLIENT_ACCESS_TOKEN = '86773b26ca554576971f45baff906bce'
DEVELOPER_ACCESS_TOKEN = '7f3918105982484c866c5891ae31972f'

# https://api.ai/docs/reference/agent/#versioning
API_VERSION = '20150910'
DIALOGFLOW = {
'client_access_token': 'e5dc21cab6df451c866bf5efacb40178',
}

# Application definition

Expand All @@ -43,21 +39,21 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_bootstrap_base_template',
'apiai_chat',
'chat',
'corsheaders',
'django_dialogflow',
)

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'apiai_chat.urls'
ROOT_URLCONF = 'django_dialogflow.urls'

TEMPLATES = [
{
Expand All @@ -75,7 +71,7 @@
},
]

WSGI_APPLICATION = 'apiai_chat.wsgi.application'
WSGI_APPLICATION = 'django_dialogflow.wsgi.application'


# Database
Expand Down Expand Up @@ -106,3 +102,10 @@
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_URL = '/static/'

CORS_ORIGIN_WHITELIST = (
'google.com',
'hostname.example.com',
'localhost:8000',
'127.0.0.1:9000'
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{% load staticfiles %}
<html>
<head>
<title>API AI</title>
<title>Django Dialogflow</title>
<link rel="stylesheet" href="{% static 'css/bootstrap.css' %}"/>
<link rel="stylesheet" href="{% static 'css/custom.css' %}"/>
</head>
<body>

<div class="container">
<div class="page-header text-center">
<h1>API.AI</h1>
<h1>Django Dialogflow</h1>
</div>

<div class="row">
Expand All @@ -32,62 +32,74 @@ <h1>API.AI</h1>
<script src="{% static 'js/js.cookie.js' %}"></script>
<script src="{% static 'js/bootstrap.js' %}"></script>
<script>
var apiAiUrl = '{% url "apiai:index" %}';
var $chatlog = $('.js-chat-log');
var $input = $('.js-text');
var $sayButton = $('.js-say');
var dialogflowUrl = '{% url "index" %}';
var csrftoken = Cookies.get('csrftoken');

function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}

$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
}
});
var $chatlog = $('.js-chat-log');
var $input = $('.js-text');
var $sayButton = $('.js-say');

function createRow(text) {
var $row = $('<li class="list-group-item"></li>');
var list = '<li class="list-group-item">'
var k = text.split("\n")

for(i=0;i<k.length;i++) {
list += k[i]+"<br />"
}

list = list + "</li>"
$row.text(list);
$chatlog.append(list);
}
window.onload = createRow('<b><font size="2" face="Lucida Console">Chat with API.AI</font></b>');

window.onload = createRow('<b><font size="2" face="Lucida Console">Chat with Dialogflow</font></b>');

function submitInput() {
var inputData = {
'text': $input.val()
}
// Display the user's input on the web page
createRow(inputData.text);
var apiAiChatUrl = '{% url "apiai:chat" %}';
var dialogflowChatUrl = '{% url "chat" %}';
var $submit = $.ajax({
url: apiAiChatUrl,
type: 'POST',
url: dialogflowChatUrl,
data: JSON.stringify(inputData),
contentType: 'application/json'
});

$submit.done(function(statement) {
createRow(statement.text);
// Clear the input field
$input.val('');
});

$submit.fail(function() {
// TODO: Handle errors
});
}

$sayButton.click(function() {
submitInput();
});

$input.keydown(function(event) {
// Submit the input when the enter button is pressed
if (event.keyCode == 13) {
submitInput();apiAiChatUrl
submitInput();dialogflowChatUrl
}
});
</script>
Expand Down
Loading

0 comments on commit 3228402

Please sign in to comment.