Actions on Google – Building a ChatBot using API.AI for Google Assistant v2

Actions on Google üzerine yazdığım ilk 2 yazı genel olarak bilgi verme amaçlıydı. 3. yazıda ise beraber basitçe bir chatbot yarattık. Ancak chatbotumuz kullanıcıya cevap olarak biz ne istersek onu verdi. Arkada herhangi bir çalışma yapılmadı, herhangi bir servise gidilip data çekilmedi. Bu yazıda ise botumuzu biraz daha akıllandıracağız.

apiai-overview

Webhook kullanabilmek için soldaki menüde yer alan fullfilment’e tıklayıp onu aktif etmemiz gerekmektedir. Gideceğimiz webservis url’ini de burada veriyor olacağız.

screen-shot-2017-02-18-at-23-42-03

Servise gelecek olan isteğin formatı aşağıdaki gibi olacaktır.

 POST https://my-service.com/action

 Headers:
 //user defined headers
 Content-type: application/json

 POST body:

{
    "lang": "en", 
    "status": {
        "errorType": "success", 
        "code": 200
    }, 
    "timestamp": "2017-02-09T16:06:01.908Z", 
    "sessionId": "1486656220806", 
    "result": {
        "parameters": {
            "city": "Rome", 
            "name": "Ana"
        }, 
        "contexts": [], 
        "resolvedQuery": "my name is Ana and I live in Rome", 
        "source": "agent", 
        "score": 1.0, 
        "speech": "", 
        "fulfillment": {
            "messages": [
                {
                    "speech": "Hi Ana! Nice to meet you!", 
                    "type": 0
                }
            ], 
            "speech": "Hi Ana! Nice to meet you!"
        }, 
        "actionIncomplete": false, 
        "action": "greetings", 
        "metadata": {
            "intentId": "9f41ef7c-82fa-42a7-9a30-49a93e2c14d0", 
            "webhookForSlotFillingUsed": "false", 
            "intentName": "greetings", 
            "webhookUsed": "true"
        }
    }, 
    "id": "ab30d214-f4bb-4cdd-ae36-31caac7a6693", 
    "originalRequest": {
        "source": "google", 
        "data": {
            "inputs": [
                {
                    "raw_inputs": [
                        {
                            "query": "my name is Ana and I live in Rome", 
                            "input_type": 2
                        }
                    ], 
                    "intent": "assistant.intent.action.TEXT", 
                    "arguments": [
                        {
                            "text_value": "my name is Ana and I live in Rome", 
                            "raw_text": "my name is Ana and I live in Rome", 
                            "name": "text"
                        }
                    ]
                }
            ], 
            "user": {
                "user_id": "PuQndWs1OMjUYwVJMYqwJv0/KT8satJHAUQGiGPDQ7A="
            }, 
            "conversation": {
                "conversation_id": "1486656220806", 
                "type": 2, 
                "conversation_token": "[]"
            }
        }
    }
}

Servisimizden dönmesi gerek yanıt ise aşağıdaki formatda olmalıdır. Bu formatta request alıp, aşağıdaki formatta response verdiğimiz sürece istediğimiz platformda geliştirme yapabiliriz. Eğer node.js’le ilerlemeyi seçerseniz, actions on google’ın github‘ında template kod bulunmakta.

Headers:
Content-type: application/json

Body:
{
"speech": "Barack Hussein Obama II is the 44th and current President of the United States.",
"displayText": "Barack Hussein Obama II is the 44th and current President of the United States, and the first African American to hold the office. Born in Honolulu, Hawaii, Obama is a graduate of Columbia University   and Harvard Law School, where ",
"data": {...},
"contextOut": [...],
"source": "DuckDuckGo"
}

Data çalışacağımız platformu ifade etmektedir.

"data": {"slack": {<slack_message>}}
"data": {"facebook": {<facebook_message>}}
"data": {"kik": {<kik_message>}}
"data": {"telegram": {<telegram_message>}}

Referanslar:

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create a free website or blog at WordPress.com.

Up ↑