For the time being, try using the docomo chat dialogue API

* Currently (2019/01/01) docomo chat dialogue API service has ended, and [Natural dialogue API](https://dev.smt.docomo.ne.jp/? It seems to be provided as part of p = docs.api.page & api_name = natural_dialogue & p_name = api_usage_scenario). Please refer to the official reference. </ font>

The second decoction is also good, but for the time being, I wanted to move docomo's chat dialogue. Eventually, I would like to use it together with the Twitter API to create a BOT that allows dialogue.

Things necessary

--Python execution environment --docomo Developer support account --docomo Chat Dialogue API API Key

Register an account from this page, enter the necessary information, check "chat dialogue", and apply. Can be obtained. I thought it was after the examination, but it will be issued immediately after the application.

Try it on the Web for the time being

You can try the API function from this page.

Communicate in json format. " Utt "2 line of the HTTP request body: Hello part is the exchange of part of the conversation. Rewrite it to your liking and press the execute button to return the result.

python


{
  "utt": "I want to eat yakiniku",
  "context": "",
  "nickname": "light",
  "nickname_y": "Hikari",
  "sex": "woman",
  "bloodtype": "B",
  "birthdateY": "1997",
  "birthdateM": "5",
  "birthdateD": "30",
  "age": "16",
  "constellations": "Gemini",
  "place": "Tokyo",
  "mode": "dialog"
}

python


{
  "utt": "Do you want to eat yakiniku? want to eat",
  "yomi": "Do you want to eat yakiniku? want to eat",
  "mode": "dialog",
  "da": "22",
  "context": "W54mlG80QNb-o95J9c7SVA"
}

About parameters

The parameters are quoted from the "See explanation" button on the upper right.

Parameters Description
utt Enter the user's utterance. 255 characters or less
context Continue the conversation by entering the context output from the system. 255 characters or less
nickname Set the user's nickname. 10 characters or less
nickname_y Sets the reading of the user's nickname. 20 full-width characters or less(Katakana only)
sex Set the gender of the user. Man or woman
bloodtype Set the user's blood type. One of A, B, AB, O
birthdateY Set the user's birthday (year). Any integer from 1 to the present(4 single-byte characters or less)
birthdateM Set the user's birthday (month). Any integer from 1 to 12
birthdateD Set the user's birthday (day). Any integer from 1 to 31
age Set the age of the user. Positive integer(3 single-byte characters or less)
constellations Set the user's constellation. One of Aries, Taurus, Gemini, Crab, Leo, Virgo, Libra, Sagittarius, Sagittarius, Capricorn, Aquarius, Pisces
place Set the user's regional information. Specifications 2.4 One of the items included in the "Location List"
mode The current mode of interaction. Continue shiritori by inputting the mode output from the system
dialog or srtr default: dialog

All the patterns of ʻutt` are indispensable. User attributes can be omitted or only partially. By setting a name, it seems that the name will be included in the reply content.

context seems to be important

The part of " context ":" W54mlG80QNb-o95J9c7SVA " in the above yakiniku conversation. If you send this context together with the next dialogue data transmission, the conversation will be connected. Obviously, it's not the first time, so it's blank in the above example.

I was wondering if the context would be different for each conversation, but it will be issued for each session (?).

Run with Python

I referred to uepon daily memorandum --try to use chat dialogue API.

docomo_dialogue.py


#!/usr/bin/env python
# -*- coding: utf-8 -*-

import requests
import json
import types

KEY = 'Enter the obtained API Key here'

#Endpoint settings
endpoint = 'https://api.apigw.smt.docomo.ne.jp/dialogue/v1/dialogue?APIKEY=REGISTER_KEY'
url = endpoint.replace('REGISTER_KEY', KEY)

#Input of the first conversation
utt_content = raw_input('>>')

payload = {'utt' : utt_content, 'context': ''}
headers = {'Content-type': 'application/json'}

#Send
r = requests.post(url, data=json.dumps(payload), headers=headers)
data = r.json()

#json analysis
response = data['utt']
context = data['context']

#display
print "response: %s" %(response)

#Second and subsequent conversations(Ctrl+End with C)
while True:
    utt_content = raw_input('>>')
    payload['utt'] = utt_content
    payload['context'] = data['context']

    r = requests.post(url, data=json.dumps(payload), headers=headers)
    data = r.json()

    response = data['utt']
    context = data['context']

    print "response: %s" %(response)

Below is the execution result.

python


>>I want to eat fish! !!
response:By the way, did you know that December 1st is a movie day?
>>Don't ignore it. .. .. I do not know.
response:Seems to be ignored
>>cold
response:No problem. is it cold?
>>It's hot
response:Patapata
>>Thank you
response:Nadenade
>>

I get an error at runtime

I was a little addicted to the fact that I get requests.exceptions.SSLError at runtime. For the time being, I solved it by the following method.

python


$ sudo pip install requests[security]

Finally

If you use this together with Twitter API, you can make Twitter BOT. For LINE, LINE BOT is also available. However, since we have to have each conversation for each user who skipped mentions, it seems difficult to deal with the processing around there.

Recommended Posts

For the time being, try using the docomo chat dialogue API
Try using LINE Notify for the time being
Try using FireBase Cloud Firestore in Python for the time being
Try using the Twitter API
Try using the Twitter API
Try using the PeeringDB 2.0 API
[Introduction to Reinforcement Learning] Reinforcement learning to try moving for the time being
Let's touch Google's Vision API from Python for the time being
Try using the Kraken API in Python
Python Master RTA for the time being
Let's try Linux for the first time
I tried using scrapy for the first time
I checked the library for using the Gracenote API
Try using the BitFlyer Ligntning API in Python
For the time being, import them into jupyter
Use logger with Python for the time being
Run yolov4 "for the time being" on windows
I played with Floydhub for the time being
virtualenv For the time being, this is all!
Try using the DropBox Core API in Python
Try posting to Qiita for the first time
Try adding an external module to pepper. For the time being, in requests.
Flow memo to move LOCUST for the time being
Run with CentOS7 + Apache2.4 + Python3.6 for the time being
I will install Arch Linux for the time being.
Next to Excel, for the time being, jupyter notebook
I will try to summarize the links that seem to be useful for the time being
I want to move selenium for the time being [for mac]
I tried running PIFuHD on Windows for the time being
Try a similar search for Image Search using the Python SDK [Search]
I tried the Google Cloud Vision API for the first time
I want to create a Dockerfile for the time being.
[For beginners] I tried using the Tensorflow Object Detection API
Java programmer tried to touch Go language (for the time being)
Understanding the python class Struggle (1) Let's move it for the time being
Challenge image classification by TensorFlow2 + Keras 1-Move for the time being-
For the time being, I want to convert files with ffmpeg !!
Try using Janus gateway's Admin API
Try using Pleasant's API (python / FastAPI)
[For self-learning] Go2 for the first time
Try using Python argparse's action API
See python for the first time
Try using the Python Cmd module
Start Django for the first time
I tried using the checkio API
Challenge image classification with TensorFlow2 + Keras CNN 1 ~ Move for the time being ~
Try sending an email with the Gmail API Client Library for Java
Try using a Linux server as a backup destination for Time Machine (Ver. 2020)
A useful note when using Python for the first time in a while
Try using the web application framework Flask
I tried tensorflow for the first time
Try using the HL band in order
Try using the camera with Python's OpenCV
Try the Microsoft Cognitive Services Face API
Tweet using the Twitter API in Python
Try using Dropbox API v2 with Go
Try cluster analysis using the K-means method
MongoDB for the first time in Python
Create an application using the Spotify API
Play with puns using the COTOHA API
Try hitting the Spotify API in Django.