swagger: "2.0"
info:
  title: "WhatYa APIs"
  version: "2.0.4"
  description: "WhatYaのチャット機能の一部を利用するためのAPI一覧です。\n
   ※APIのみを利用してV2機能(オペレーターと接続・会話)を利用する場合、別サーバーを必要とします。\n
   この場合、通常の通信方式(Websocket)とは異なり、Webfookを利用した連携接続となります。\n
   別途ご相談ください。"
  termsOfService: ""
  contact:
    email: "info@solairo.co.jp"
  license:
    name: "SOLAIRO,Inc."
    url: "https://www.solairo.co.jp"
#host: "--"
#basePath: "/"
tags:
- name: "sign_in"
  description: "room in"
- name: "get_messages"
  description: "history messages."
- name: "post_message"
  description: "send message."
- name: "post_invoke"
  description: "send invoke message."  
schemes:
- "https"

paths:
  ######################################
  # SIGN IN (Login room)
  ######################################
  /put/signin (room in):
    put:
      tags:
      - "sign_in"
      summary: "roomへサインインを行います。"
      description: 
        "※ID&PWの組み合わせで、Session情報が見つからなかった場合、新規ユーザー登録(サインアップ)を行います。\n
        ※ID & PWを持たない(Anonymous)ユーザーの場合、常にIDとPWは、Nullで設定します。\n
         内部で自動的にIDとPWを生成し、ルームの利用を開始させることが出来ます。\n
         また、Anonymousユーザーをログインユーザーに変更させたい場合、\n
         付与されたtoken(localstorageに保存)と共にID & PW
         を送信することで、同じルームを利用することが可能です。\n
        ※有効期限が過ぎたTokenを持っているSession情報を検索した場合、自動的にTokenが最新のものへ切り換わります。\n"
      operationId: "SignIn"
      consumes:
      - "application/json"
      produces:
      - "application/json"
      parameters:
      - name: "version"
        in : "query"
        required: true
        type: "string"
        description: "2020.10.21 最新は2.0.5_cp_p2。この場合、2.0までが一致することで後方互換性のあるAPIの利用が可能。"
      - name: "domain"
        in : "query"
        required: true
        type: "string"
        description: "送信元のFQDNを判定します。ホワイトリストの登録が必要となります。"
      - name: "id"
        in : "query"
        required: true
        type: "string"
        description: "Anonymousユーザーの場合、Nullで送信します。"
      - name: "pw"
        in : "query"
        required: true
        type: "string"
        description: "Anonymousユーザーの場合、Nullで送信します。"
      - name: "token"
        in : "query"
        required: false
        type: "string"
        description: "初回:null, 2回目以降:付与されたtokenで送信します。"
      - in: "body"
        name: "Request body"
        description: "Json parameters."
        required: false
        schema:
          $ref: "#/definitions/ReqSignIn"
          
      responses:
        200:
          description: "Status Code [200] successful operation \n
                          [初回] \n
                        id、pwの組み合わせで、初めての問い合わせの場合、\n
                        または、id、pw、tokenがすべてnullの組み合わせの場合"
          schema:
            $ref: "#/definitions/ResSignIn_SignUp"
        201:
          description: "Status Code [200] successful operation \n
                        [二回目以降] \n
                        id, pwの組み合わせが、登録済、且つTokenの有効期限内の場合、\n
                        または、id、pwがnull、tokenが設定されている、且つTokenの有効期限内の場合"
          schema:
            $ref: "#/definitions/ResSignIn_SignIn"
        202:
          description: "Status Code [200] successful operation \n
                        [Token有効期限切れ] \n
                        id, pwの組み合わせが、登録済されている、且つTokenの有効期限外の場合"
          schema:
            $ref: "#/definitions/ResSignIn_Expired"
        203:
          description: "Status Code [200] successful operation \n
                        [PW変更、ログインユーザーへ] \n
                        PWを変更した場合や、Anonymousユーザーからログインユーザーへ変更した場合"
          schema:
            $ref: "#/definitions/ResSignIn_PwReplace"            
            
  ######################################
  # GET MESSAGES
  ######################################
  /get/messages:
    get:
      tags:
      - "get_messages"
      summary: "過去会話を取得します。"
      description: 
        "※ルームへサインイン済であり、有効なTokenを保持していることが条件。\n
        ※取得したいメッセージ位置を指定(mtime:unixtime)し、\n
         不等号パラメーター(eqsign)を用いて、取得した件数(qty)を指定します。"
      externalDocs:
        description: "See request detail spec「WhatYa response samples」"
        url: "https://solairo.atlassian.net/wiki/spaces/WHAT1/pages/138149889/Whatya+response+examples"
      operationId: "GetMessages"
      consumes:
      - "application/json"
      produces:
      - "application/json"
      parameters:
      - name: "version"
        in : "query"
        required: true
        type: "string"
        description: "2020.10.21 最新は2.0.5_cp_p2。この場合、2.0までが一致することで後方互換性のあるAPIの利用が可能。"        
      - name: "domain"
        in : "query"
        required: true
        type: "string"
        description: "送信元のFQDNを判定します。ホワイトリストの登録が必要となります。"        
      - name: "token"
        in : "query"
        required: true
        type: "string"
        description: "sign in時に付与された(local storage)ものを利用。"
      - name: "mtime"
        in : "query"
        required: true
        type: "integer"
        description: "メッセージID(発話したunixtime)"
      - name: "eqsign"
        in : "query"
        required: false
        type: "string"
        description: "不等号 lt:(<), gt:(>) eq:(=), le:(<=), ge(>=) (省略の場合、lt)"
      - name: "qty"
        in : "query"
        required: false
        type: "integer"
        description: "取得したいメッセージ数 (省略の場合、10件)"
      - name: "asc"
        in : "query"
        required: false
        type: "string"
        description: "順番 デフォルトで降順、昇順にしたい場合、true"
      - in: "body"
        name: "Request body"
        description: "Json parameters."
        required: false
        schema:
          $ref: "#/definitions/ReqGetMessages"
      responses:
        200:
          description: "デフォルトでは降順、10件、直近を取得\n
                       message配列内のおbジェクトの仕様については、「WhatYa response samples」を参照
                       "
          schema:
            $ref: "#/definitions/ResGetMessages"
            
  ######################################
  # POST MESSAGE
  ######################################
  /post/message:
    post:
      tags:
      - "post_message"
      summary: "会話を送信します。"
      description: 
        "※ルームへサインイン済であり、有効なTokenを保持していることが条件。\n"
   
      externalDocs:
        description: "See request detail spec「WhatYa response samples」"
        url: "https://solairo.atlassian.net/wiki/spaces/WHAT1/pages/138149889/Whatya+response+examples"
      operationId: "PostMessage1"
      consumes:
      - "application/json"
      produces:
      - "application/json"
      parameters:
      - name: "version"
        in : "query"
        required: true
        type: "string"
        description: "2020.10.21 最新は2.0.5_cp_p2。この場合、2.0までが一致することで後方互換性のあるAPIの利用が可能。"        
      - name: "domain"
        in : "query"
        required: true
        type: "string"
        description: "送信元のFQDNを判定します。ホワイトリストの登録が必要となります。"        
      - name: "token"
        in : "query"
        required: true
        type: "string"
        description: "sign in時に付与された(local storage)ものを利用。"
      - name: "talk.type"
        in: "query"
        type: "string"
        description: "表示するメッセージタイプ"
      - name: "talk.content.message"
        in: "query"
        type: "string"
        description: "メッセージ文言"
      - name: "talk.content.value"
        in: "query"
        type: "string"
        description: "メッセージとは異なる値を送信したい場合に指定。以外は、nullを指定。"
      - in: "body"
        name: "Request body"
        description: "json parameters."
        required: false
        schema:
          $ref: "#/definitions/ReqPostMessage"
      responses:
        200:
          description: "Status Code [200] successful operation \n
                        message配下の仕様について、「WhatYa response samples」を参照"
          schema:
            $ref: "#/definitions/ResPostMessage"

  ######################################
  # POST INVOKE
  ######################################
  /post/invoke:
    post:
      tags:
      - "post_invoke"
      summary: "Invokeをメッセージ(非表示)送信します。"
      description: 
        "※様々な用途開発のために、準備されたAPIです。シナリオを進めていく上で、ユーザー側で必要なタイミングに送信内容を\n
         画面上に表示することなく、APIサーバーからアクションをキックするために使用します。\n
         ※デフォルトでは、init_bot, init_opを標準装備しています。以下にその利用例を示します。\n\n
        利用方法例:\n
        ・init:ルームインの時やオペレーター接続時に、Botから自動投稿文を投げさせたい場合などに利用\n
 ※顧客別に自動投稿を行うまでの間隔(秒、分、時、日)を設定することが可能です(推奨1日以上〜   )。\n
 ※APIサーバーへのご登録依頼が必要となります。\n"

      externalDocs:
        description: "See request detail spec「WhatYa response samples」"
        url: "https://solairo.atlassian.net/wiki/spaces/WHAT1/pages/138149889/Whatya+response+examples"
      operationId: "InvokeMessage1"
      consumes:
      - "application/json"
      produces:
      - "application/json"
      parameters:
      - name: "version"
        in : "query"
        required: true
        type: "string"
        description: "2020.10.21 最新は2.0.5_cp_p2。この場合、2.0までが一致することで後方互換性のあるAPIの利用が可能。"        
      - name: "domain"
        in : "query"
        required: true
        type: "string"
        description: "送信元のFQDNを判定します。ホワイトリストの登録が必要となります。"        
      - name: "token"
        in : "query"
        required: true
        type: "string"
        description: "sign in時に付与された(local storage)ものを利用。"
      - name: "send_to"
        in : "query"
        required: true
        type: "string"
        description: "Botへ接続の場合、botを指定。オペレーター接続の場合、operatorを指定。"
      - name: "type"
        in : "query"
        required: true
        type: "string"
        description: "自動投稿の場合、initを指定"
      - name: "content.last_mtime"
        in : "query"
        required: true
        type: "integer"
        description: "起動する処理に応じた値のオブジェクト\n
                      initの場合、デフォルトでlast_time : nullを設定"
      - in: "body"
        name: "Request body"
        description: "json parameters."
        required: false
        schema:
          $ref: "#/definitions/ReqPostInvoke"
      responses:
        200:
          description: "Status Code [200] successful operation \n
                        "
          schema:
            $ref: "#/definitions/ResInvokeMessage"

##############################################################################
# MODEL
##############################################################################
definitions:

  ######################################
  # SIGN IN
  ######################################
  ReqSignIn:
    type: "object"
    properties:
      version:
        type: "string"
        example: "2.0.0"
        description: "Application version"
      domain:
        type: "string"
        example: "whatya.solairo-api.com"
      id:
        type: "string"
        example: "xxxxxxxxx or null"
      pw:
        type: "string"
        example: "xxxxxxxxxx or null"
      token:
        type: "string"
        example: "asdfaAD/XMXdWVtdis9MWvJfdhj4w3arouRH+eZuYpYa7dbgyadnelNFZcN/9..... or null"
  ######################################
  # SIGN IN
  ######################################
  #Request
  ResSignIn_SignUp:
    type: "object"
    properties:
      type:
        type: "string"
        example: "API"
        description: ""
      status_code:
        type: "integer"
        example: "0"
      status:
        type: "string"
        example: "Sign Up Success"
      token:
        type: "string"
        example: "xxxxxxxxxxXMXdWVtdis9MWvJfdhj4w3ardRnzo8ouRH+eZuYpYa7dbgyadnelNFZcN/9....."
        description: ""
  #Response
  ResSignIn_SignIn:
    type: "object"
    properties:
      type:
        type: "string"
        example: "API"
        description: ""
      status_code:
        type: "integer"
        example: "0"
      status:
        type: "string"
        example: "Sign In Success"
      token:
        type: "string"
        example: "xxxxxxxxxxXMXdWVtdis9MWvJfdhj4w3ardRnzo8ouRH+eZuYpYa7dbgyadnelNFZcN/9....."
        description: ""
  ResSignIn_Expired:
    type: "object"
    properties:
      type:
        type: "string"
        example: "API"
        description: ""
      status_code:
        type: "integer"
        example: "0"
      status:
        type: "string"
        example: "Session replace Success"
      token:
        type: "string"
        example: "xxxxxxxxxxc7K9rFKo6FQeXdwX/jlrPgU8fq9YVLnXvNYp8tLXmWeKvp2re6/qGqQINqsUA....."
        description: ""
  ResSignIn_PwReplace:
    type: "object"
    properties:
      type:
        type: "string"
        example: "API"
        description: ""
      status_code:
        type: "integer"
        example: "0"
      status:
        type: "string"
        example: "Session replase Success"
      token:
        type: "string"
        example: "xxxxxxxxxxc7K9rFKo6FQeXdwX/jlrPgU8fq9YVLnXvNYp8tLXmWeKvp2re6/qGqQINqsUAfF....."
        description: ""
        
  ######################################
  # GET MESSAGES
  ######################################
  #Request
  ReqGetMessages:
    type: "object"
    properties:
      version:
        type: "string"
        example: "2.0.5"
        description: "Application versioning"
      domain:
        type: "string"
        example: "whatya.solairo-api.com"
      token:
        type: "string"
        example: "xxxxxxxxxxXMXdWVtdis9MWvJfdhj4w3ardRnzo8ouRH+eZuYpYa7dbgyadnelNFZcN/9....."
      mtime:
        type: "integer"
        example: "1573809193566"
      eqsign:
        type: "string"
        example: "lt"
      qty:
        type: "integer"
        example: 10
      asc:
        type: "boolean"
        example: false
  #Response
  ResGetMessages:
    type: "object"
    properties:
      type:
        type: "string"
        example: "API"
      status_code:
        type: "integer"
        example: 0
      status:
        type: "string"
        example: "Session replase Success."
      qty:
        type: "integer"
        example: 2
      messages:
        type: "object"
        properties:
          mtime:
            type: "integer"
            example: 1573809193566
          mtype:
            type: "string"
            example: "bot"
          talk:
            type: "object"
            properties:
              content:
                type: "object"
                properties:
                  message:
                    type: "string"
                    example: "Hello!!"
        example:
          - mtime: 1573809193566
            mtype: "bot"
            talk:
              type: "text"
              content:
                messages : "Hello!!"
            cdt: "2018-12-09T15:29:42.874Z"
          - mtime: "1573809193570"
            mtype: "bot"
            talk:
              type: "text"
              content:
                messages : "Nice to meet you."
            cdt: "2018-12-09T15:29:43.904Z"
            
  ######################################
  # POST MESSAGE
  ######################################
  #Request
  ReqPostMessage:
    type: "object"
    properties:
      version:
        type: "string"
        example: "2.0.0"
        description: "Application version"
      domain:
        type: "string"
        example: "whatya.solairo-api.com"
      token:
        type: "string"
        example: "xxxxxxxxxxXMXdWVtdis9MWvJfdhj4w3ardRnzo8ouRH+eZuYpYa7dbgyadnelNFZcN/9....."
        description: ""
      client_id:
        type: "string"
        example: ""
        description: "プレ環境利用時に指定。※本番環境は、不要。"
      talk:
        type: "object"
        properties:
          type:
            type: "string"
            example: "text"
          content:
            type: "object"
            properties:
              message:
                type: "string"
                example: "こんにちは"
              value:
                type: "string"
                example: "挨拶"
  #Response
  ResPostMessage:
    type: "object"
    properties:
      type:
        type: "string"
        example: "API"
      status_code:
        type: "integer"
        example: 0
      status:
        type: "string"
        example: "Success."
      qty:
        type: "integer"
        example: 1
      messages:
        type: "array"
        items:
          type: "object"
          properties:
            mtime:
              type: "integer"
              description: "発話時間のエポックタイム(13桁)"
              example: 1573809193566
            mtype:
              type: "string"
              description: "発話者種類(bot, customer, operator)"
              example: "bot"
            talk:
              type: "object"
              description: "メッセージを格納オブジェクト"
              properties:
                content:
                  type: "object"
                  properties:
                    message:
                      type: "string"
                      description: "表示するメッセージを格納"
                      example: "Nice to meet you."
            response_context:
              type : "object"
              description: "会話継続に必要な情報を格納"
              properties:
                response_context:
                  type: "string"
                  description: "初期設定レスポンスコンテキスト(初会話時にシステム処理された空のテキスト=初回以降、処理に使用しない)"
                conversation_id:
                  type: "string"
                  description: "Aiの中で設定されている会話ID"
                system:
                  type: "object"
                  description: "Aiの中で利用するシステムオブジェクト(動的な要素説明は省略)。"
            cdt:
              type: "string"
              example: "2019-11-15T09:14:17.801Z"
          example:
            - mtime: 1573809193566
              mtype: "bot"
              talk:
                type: "text"
                content:
                  messages: "Nice to meet you."
              response_context:
                response_context:
                conversation: "637b29b9-1a83-4227-94c1-76e347bb5d3e"
                system:
                  initialized: true
                  dialog_stack :
                  - dialog_node: "root"
                  dialog_turn_counter: 2
                  dialog_request_counter: 2
                  _node_output_map:
                    node_2_1566205354871:
                    - 0
                    その他:
                    - 0
                    branch_exited: true
                  branch_exited_reason: "completed"
              cdt: "2018-12-09T15:29:43.904Z"
      newest:
        description: "デフォルト:null。Newest機能を使用した場合にコンテンツが挿入されます。"
        type: "object"
        properties:
          type:
            type: "string"
            example: "normal"
          update_at: 
            type: "integer"
            example: 1574246097042
          content:
            type: "object"
            properties:
              message:
                type: "string"
                example: "最新情報だよ"
              value:
                type: "string"
                example: "LINKAGE-Newone"            
                
  
  ######################################
  # POST INVOKE
  ######################################
  #Request
  ReqPostInvoke:
    type: "object"
    properties:
      version:
        type: "string"
        example: "2.0.0"
        description: "Application version"
      domain:
        type: "string"
        example: "whatya.solairo-api.com"
      token:
        type: "string"
        example: "xxxxxxxxxxXMXdWVtdis9MWvJfdhj4w3ardRnzo8ouRH+eZuYpYa7dbgyadnelNFZcN/9....."
      send_to:
        type: "string"
        example: "bot"
      content:
        type: "object"
        properties:
          type:
            type: "string"
            example: "init"
          last_time:
            type: "integer"
            example: "null"
  #Response
  ResInvokeMessage:
    type: "object"
    properties:
      type:
        type: "string"
        example: "API"
      status_code:
        type: "integer"
        example: 0
      status:
        type: "string"
        example: "Success."
      qty:
        type: "integer"
        example: 1
      messages:
        type: "array"
        items:
          type: "object"
          properties:
            mtime:
              type: "integer"
              description: "発話時間のエポックタイム(13桁)"
              example: 1573809193566
            mtype:
              type: "string"
              description: "発話者種類(bot, customer, operator)"
              example: "bot"
            talk:
              type: "object"
              description: "メッセージを格納オブジェクト"
              properties:
                content:
                  type: "object"
                  properties:
                    message:
                      type: "string"
                      description: "表示するメッセージを格納"
                      example: "Welcome."
            response_context:
              type : "object"
              description: "会話継続に必要な情報を格納(Post messageと同義)"
              properties:
                response_context:
                  type: "string"
                  description: "初期設定レスポンスコンテキスト(初会話時にシステム処理された空のテキスト=初回以降、処理に使用しない)"
                conversation_id:
                  type: "string"
                  description: "Aiの中で設定されている会話ID"
                system:
                  type: "object"
                  description: "Aiの中で利用するシステムオブジェクト(動的な要素説明は省略)。"
            cdt:
              type: "string"
              example: "2019-11-15T09:14:17.801Z"
      newest:
        description: "デフォルト:null。Newest機能を使用した場合にコンテンツが挿入されます。"
        type: "object"
        properties:
          type:
            type: "string"
            example: "normal"
          update_at: 
            type: "integer"
            example: 1574246097042
          content:
            type: "object"
            properties:
              message:
                type: "string"
                example: "最新情報だよ"
              value:
                type: "string"
                example: "LINKAGE-Newone"
  
externalDocs:
  description: "Find out more about Swagger"
  url: "http://swagger.io"