網站智能陪聊客服的實現

來源:互聯網
上載者:User

標籤:

因為藉助到圖靈機器人的API,其自身具有智能聊天和自訂知識庫的功能,所以開發起來非常的簡單,調用介面即可。可以放在網站中作為智能陪聊客服,來為訪客解答問題或者陪聊天。該代碼以Java開發為例,編寫一個簡單的網頁,主要開發過程見代碼,會有簡單的描述。

編寫一個簡單的jsp頁面,用於和自己的項目後台互動,提交請求內容、接收顯示處理結果 

function doSubmit(){             var info = $(‘#info‘).val()              var url=‘自己項目的後台介面(如servlet)‘;                  $.get(url, {              info : info,              key : 註冊圖靈機器人帳號擷取key          },   function(json) {                      if(json != null){                                 alert(json);                                 document.getElementById("res").innerText = json;                      }else{                                document.getElementById("res").innerText = ‘無傳回值‘;    }            }    );      }

 項目後台接收頁面請求內容,調用圖靈api介面,返回處理結果(核心邏輯代碼)

/** 調用圖靈機器人平台介面http://www.tuling123.com/openapi/cloud/access_api.jsp* 需要匯入的包:commons-logging-1.0.4.jar、 httpclient-4.3.1.jar、httpcore-4.3.jar  */ public static void main(String[] args) throws IOException {        String APIKEY = "開發人員註冊帳號,啟用之後即可獲得";       String INFO = URLEncoder.encode("北京今日天氣", "utf-8");      String requesturl = "http://www.tuling123.com/openapi/api?key="+APIKEY+"&info="+INFO;      HttpGet request = new HttpGet(requesturl);      HttpResponse response = HttpClients.createDefault().execute(request);       //200即正確的返回碼     if(response.getStatusLine().getStatusCode()==200){          String result = EntityUtils.toString(response.getEntity());          System.out.println("返回結果:"+result);      }  }

 

網站智能陪聊客服的實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.