Skip Navigation
Expand
チャットAPI実例チャットセッション
Answer ID 9457   |   Last Review Date 01/27/2019

チャットAPIチャットセッションの実例がありますか?

環境:

チャットAPI

対策:

下記には簡単なチャットAPIチャットセッションの実例を紹介します。基本的にチャットAPIの呼び出しはwsdlにて作成されますが、下記はSoapUIで送信された基本なsoap envelopeと簡単なチャットセッションになります。解説のためです。

注意:チャットAPIの呼び出しをテストするため、無料版のSoapUIをインストールしてください。インストール後、ファイル→新しいSOAPプロジェクトを開き、お客様サイトのチャットwsdlを入れます。ー例:http://<site>/cgi-bin/<interface>.cfg/services/chat_soap?wsdl

下記は行われたステップのハイレベル概要です。

--> GetChatUrl
     chat_soap?wsdlのエンドポイントを送信する.
<-- ChatUrlResponseを返す, ChatUrl, ChatToken とSiteNameを含む.

--> RequestChat
     この前のステップよりChatUrlへ送信する、この前のステップよりChatToken と SiteName fromへまわす。
<-- SessionIDを含んだRequestChatResponseを返す

--> RetrieveMessages
     この前のステップよりChatUrlへ送信し、この前のステップよりSessionIDへまわす.
<-- messagesを含んだRetrieveMessagesResponseを返す

--> PostChatMessage
     この前のステップよりChatUrlへ送信し、 この前のステップよりSessionIDへまわす.
<-- messagesを含んだPostChatMessageResponseを返す

--> TerminateChat
     この前のステップよりChatUrlへ送信し、 この前のステップよりSessionIDへまわす.
<-- チャット終了の TerminateChatResponse を返す

ステップ1:  GetChatUrl

Request:

<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rncm="urn:messages.chat.ws.rightnow.com/v1_2" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ins0="urn:fault.ws.rightnow.com/v1_2">
   <env:Header>
     <ClientRequestHeader xmlns="urn:messages.chat.ws.rightnow.com/v1_2">
      <AppID>Sample Chat Client</AppID>
   </ClientRequestHeader>
   <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-1">
         <wsse:Username>YourUserID</wsse:Username>
         <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">XXXXX</wsse:Password>
         </wsse:UsernameToken>
      </wsse:Security>
   </env:Header>
   <env:Body>
     <rncm:GetChatUrl>
      <rncm:UrlType>ENDUSER</rncm:UrlType>
      <rncm:Version>1.2</rncm:Version>
   </rncm:GetChatUrl>
</env:Body>
</env:Envelope>

Response:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
      <n0:GetChatUrlResponse xmlns:n0="urn:messages.chat.ws.rightnow.com/v1_2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <n0:GetChatUrlResult>
            <n0:ChatUrl>CHAT_URL_WILL_BE_HERE</n0:ChatUrl>
            <n0:ChatToken>1234a5b6-c789-01d2-345-678ef90a1bc2</n0:ChatToken>
            <n0:SiteName>YOUR_SITE_NAME</n0:SiteName>
         </n0:GetChatUrlResult>
      </n0:GetChatUrlResponse>
   </soapenv:Body>
</soapenv:Envelope>

(make note of the ChatUrl, ChatToken, and SiteName.  You'll be using those in another call)

 

ステップ2:  RequestChat

(Sent to CHAT_URL_WILL_BE_HERE, returned above)

Request:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="urn:messages.common.chat.ws.rightnow.com/v1" xmlns:v11="urn:messages.enduser.chat.ws.rightnow.com/v1">
   <soapenv:Header>
      <v1:ChatClientInfoHeader>
         <v1:AppID>Sample Chat Client</v1:AppID>
      </v1:ChatClientInfoHeader>
      <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1">
         <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-3902281">
            <wsse:Username>YourUserName</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">XXXXX</wsse:Password>
         </wsse:UsernameToken>
      </wsse:Security>
   </soapenv:Header>
   <soapenv:Body>
      <v11:RequestChat>
         <v11:TransactionRequestData>
            <v11:ClientRequestTime>2015-03-07 11:34:00</v11:ClientRequestTime>
            <v11:ClientTransactionID>2</v11:ClientTransactionID>
            <v11:SiteName>YOUR_SITE_NAME</v11:SiteName>
         </v11:TransactionRequestData>
         <v11:CustomFields>
            <ObjectType>
               <TypeName>ContactCustomFields</TypeName>
            </ObjectType>
            <v1:GenericFields dataType="OBJECT" name="c">
               <DataValue>
                  <ObjectValue>
                     <ObjectType>
                        <TypeName>IncidentCustomFieldsc</TypeName>
                     </ObjectType>
                     <GenericFields dataType="STRING" name="priority">
                        <DataValue>
                           <StringValue>very high</StringValue>
                        </DataValue>
                     </GenericFields>
                  </ObjectValue>
               </DataValue>
            </v1:GenericFields>
         </v11:CustomFields>
         <v11:CustomerInformation>
            <v1:EMailAddress>name@email.invalid</v1:EMailAddress>
            <v1:FirstName>First</v1:FirstName>
            <v1:LastName>Last</v1:LastName>
            <v1:InterfaceID>
               <v1:ID id="1"/>
            </v1:InterfaceID>
         </v11:CustomerInformation>
         <v11:ChatSessionToken>1234a5b6-c789-01d2-345-678ef90a1bc2</v11:ChatSessionToken> <-- Must match the Token above!
      </v11:RequestChat>
   </soapenv:Body>
</soapenv:Envelope>

Response:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns3:RequestChatResponse xmlns="urn:messages.common.chat.ws.rightnow.com/v1" xmlns:ns2="urn:messages.uq.chat.ws.rightnow.com/v1" xmlns:ns3="urn:messages.enduser.chat.ws.rightnow.com/v1" xmlns:ns4="urn:faults.chat.ws.rightnow.com/v1">
         <ns3:TransactionResponseData>
            <ns3:ServiceStartTime>2015-11-10T18:41:12.654Z</ns3:ServiceStartTime>
            <ns3:ServiceFinishTime>2015-11-10T18:41:13.086Z</ns3:ServiceFinishTime>
            <ns3:ClientID>123</ns3:ClientID>
            <ns3:ClientTransactionID>2</ns3:ClientTransactionID>
         </ns3:TransactionResponseData>
         <ns3:EngagementID id="123"/>
         <ns3:CancelledSurveyID id="0"/>
         <ns3:CompletedSurveyID id="0"/>
         <ns3:ResultType>SUCCESS</ns3:ResultType>
         <ns3:SessionID>12a3bcdefghi4jk56lmn7o8pq</ns3:SessionID>  <--Will be used in future calls
      </ns3:RequestChatResponse>
   </S:Body>
</S:Envelope>

 

ステップ3:  RetrieveMessages

Request:

<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsdl="urn:messages.enduser.chat.ws.rightnow.com/v1" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
  <env:Header>
    <ChatClientInfoHeader xmlns="urn:messages.common.chat.ws.rightnow.com/v1">
      <AppID>Sample Chat Client</AppID>
      <SessionID>12a3bcdefghi4jk56lmn7o8pq</SessionID>
    </ChatClientInfoHeader>
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-1">
        <wsse:Username>YourUserName</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">XXXXX</wsse:Password>
      </wsse:UsernameToken>
    </wsse:Security>
  </env:Header>
  <env:Body>
    <wsdl:RetrieveMessages>
      <TransactionRequestData>
        <ClientRequestTime>11:30:20</ClientRequestTime>
        <ClientTransactionID>2</ClientTransactionID>
        <SiteName>YourSiteName</SiteName>
      </TransactionRequestData>
    </wsdl:RetrieveMessages>
  </env:Body>
</env:Envelope>

Response:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns3:RetrieveMessagesResponse xmlns="urn:messages.common.chat.ws.rightnow.com/v1" xmlns:ns2="urn:messages.uq.chat.ws.rightnow.com/v1" xmlns:ns3="urn:messages.enduser.chat.ws.rightnow.com/v1" xmlns:ns4="urn:faults.chat.ws.rightnow.com/v1">
         <ns3:TransactionResponseData>
            <ns3:ClientRequestTime/>
            <ns3:ServiceStartTime>2015-11-10T18:42:47.019Z</ns3:ServiceStartTime>
            <ns3:ServiceFinishTime>2015-11-10T18:42:47.033Z</ns3:ServiceFinishTime>
            <ns3:ClientID>860</ns3:ClientID>
            <ns3:ClientTransactionID>2</ns3:ClientTransactionID>
         </ns3:TransactionResponseData>
         <ns3:SystemMessages>
            <ns3:RNChatParticipantAddedMessage>
               <CreatedTime>2015-11-10T18:41:31.176Z</CreatedTime>
               <ns3:Name>First Last</ns3:Name>
               <ns3:Greeting>Hi, my name is Joe Smith. How may I help you?</ns3:Greeting>
               <ns3:ClientID>123</ns3:ClientID>
               <ns3:Role>LEAD</ns3:Role>
            </ns3:RNChatParticipantAddedMessage>
            <ns3:RNChatMessagePostedMessage>
               <CreatedTime>2015-11-10T18:42:01.645Z</CreatedTime>
               <ns3:Body>test response</ns3:Body>
               <ns3:ClientID>123</ns3:ClientID>
            </ns3:RNChatMessagePostedMessage>
         </ns3:SystemMessages>
      </ns3:RetrieveMessagesResponse>
   </S:Body>
</S:Envelope>

 

ステップ4: PostChatMessage

Request

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="urn:messages.common.chat.ws.rightnow.com/v1" xmlns:v11="urn:messages.enduser.chat.ws.rightnow.com/v1">
   <soapenv:Header>
    <ChatClientInfoHeader xmlns="urn:messages.common.chat.ws.rightnow.com/v1">
      <AppID>Sample Chat Client</AppID>
      <SessionID>12a3bcdefghi4jk56lmn7o8pq</SessionID>
    </ChatClientInfoHeader>
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-1">
        <wsse:Username>YourUserName</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">XXXXX</wsse:Password>
      </wsse:UsernameToken>
    </wsse:Security>
   </soapenv:Header>
   <soapenv:Body>
      <v11:PostChatMessage>
         <v11:TransactionRequestData>
            <v11:ClientRequestTime>11:30:20</v11:ClientRequestTime>
            <v11:ClientTransactionID>2</v11:ClientTransactionID>
            <v11:SiteName>YourSiteName</v11:SiteName>
         </v11:TransactionRequestData>
         <v11:Body>This is a PostChatMessage message!</v11:Body>
      </v11:PostChatMessage>
   </soapenv:Body>
</soapenv:Envelope>

Response

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns3:PostChatMessageResponse xmlns="urn:messages.common.chat.ws.rightnow.com/v1" xmlns:ns2="urn:messages.uq.chat.ws.rightnow.com/v1" xmlns:ns3="urn:messages.enduser.chat.ws.rightnow.com/v1" xmlns:ns4="urn:faults.chat.ws.rightnow.com/v1">
         <ns3:TransactionResponseData>
            <ns3:ClientRequestTime/>
            <ns3:ServiceStartTime>2015-11-10T20:23:44.553Z</ns3:ServiceStartTime>
            <ns3:ServiceFinishTime>2015-11-10T20:23:44.563Z</ns3:ServiceFinishTime>
            <ns3:ClientID>123</ns3:ClientID>
            <ns3:ClientTransactionID>2</ns3:ClientTransactionID>
         </ns3:TransactionResponseData>
      </ns3:PostChatMessageResponse>
   </S:Body>
</S:Envelope>

 

Step 5: TerminateChat

Request:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="urn:messages.common.chat.ws.rightnow.com/v1" xmlns:v11="urn:messages.enduser.chat.ws.rightnow.com/v1">
   <soapenv:Header>
    <ChatClientInfoHeader xmlns="urn:messages.common.chat.ws.rightnow.com/v1">
      <AppID>Sample Chat Client</AppID>
      <SessionID>12a3bcdefghi4jk56lmn7o8pq</SessionID>
    </ChatClientInfoHeader>
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-1">
        <wsse:Username>YourUserName</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">XXXXX</wsse:Password>
      </wsse:UsernameToken>
    </wsse:Security>
   </soapenv:Header>
   <soapenv:Body>
      <v11:TerminateChat>
         <v11:TransactionRequestData>
            <v11:ClientRequestTime>?</v11:ClientRequestTime>
            <v11:ClientTransactionID>2</v11:ClientTransactionID>
            <v11:SiteName>YourSiteName</v11:SiteName>
         </v11:TransactionRequestData>
      </v11:TerminateChat>
   </soapenv:Body>
</soapenv:Envelope>

Response:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns3:TerminateChatResponse xmlns="urn:messages.common.chat.ws.rightnow.com/v1" xmlns:ns2="urn:messages.uq.chat.ws.rightnow.com/v1" xmlns:ns3="urn:messages.enduser.chat.ws.rightnow.com/v1" xmlns:ns4="urn:faults.chat.ws.rightnow.com/v1">
         <ns3:TransactionResponseData>
            <ns3:ServiceStartTime>2015-11-10T20:25:16.090Z</ns3:ServiceStartTime>
            <ns3:ServiceFinishTime>2015-11-10T20:25:16.127Z</ns3:ServiceFinishTime>
            <ns3:ClientID>123</ns3:ClientID>
            <ns3:ClientTransactionID>2</ns3:ClientTransactionID>
         </ns3:TransactionResponseData>
      </ns3:TerminateChatResponse>
   </S:Body>
</S:Envelope>

 

関連リンク:

チャットAPIの開発ガイド

Available Languages for this Answer:

Notify Me
The page will refresh upon submission. Any pending input will be lost.