---
sourceDocument: オーストラリア API リファレンス
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ja-JP/api-reference

 Release :

    - australia

ft:locale :

    - ja-JP

ft:publication_title :

    - オーストラリア API リファレンス

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# ライブエージェントチャットと仮想エージェントチャットにコンテキスト変数を渡す

# ライブエージェントチャットと仮想エージェントチャットにコンテキスト変数を渡す {#ariaid-title1}

* リリースバージョン: Australia
* 
* 更新日 2026年03月12日
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 所要時間：5分

contextData パラメーターを渡すことで、チャットセッションを開始するときにチャットコンテキスト変数を渡すことができます。
この値は、 [NowChatService - startChat(contextData: \[文字列: 任意\]? = nil, _ completion: @escaping (結果\<無効, NowChatServiceError\>) -\> 無効)](3BIGTN_cKzccpzZLGLOcjQ#NChatServ-startChat_O "チャットセッションを開始し、チャットセッションの開始後に完了ブロックを実行します。") 関数を使用して渡すことができます。

チャットコンテキスト変数の詳細については、「 [Live agent chat context variables](https://www.servicenow.com/docs/access?context=live-agent-chat-context-vars&version=australia&pubname=australia-conversational-interfaces&ft:locale=en-US)」を参照してください。

さらに、チャットセッションを開始するときにオプションの NowChatConfiguration パラメーターを渡して、NowChat の動作の一部を変更することもできます。  
* closePrompt:チャットウィンドウを終了する前に表示するプロンプトテキスト。このプロンプトテキストは、次のパラメーターを使用して定義します。
  * header:プロンプトのヘッダーに表示される null 許容の文字列値。
  * message:プロンプトの本文に表示される文字列値。
  * acceptButtonTitle:プロンプトのプライマリボタンに表示される文字列値。このボタンをクリックすると、チャットウィンドウが閉じます。
  * declineButtonTitle:プロンプトのセカンダリボタンに表示される文字列値。このボタンは、チャットウィンドウを閉じずにプロンプトを閉じます。
  {#mobsdk-ios-pass-con-variables__ul_gm3_wyb_fdc}
* disabledFeatures:無効にする NowChat 機能のリスト。無効にできる機能のリストについては、 NowChatConfiguration.Feature 列挙型クラスを参照してください。
* conversationOptions:NowChat に適用する会話オプションのリスト。適用できるオプションのリストについては、 NowChatConvestation.ConversationOption 列挙型クラスを参照してください。
* uiConfiguration:NowChat で UI コンポーネントを構成するために使用される UIConfiguration 値。
{#mobsdk-ios-pass-con-variables__ul_v4q_lyj_kbc}  
次のコード例は、このメソッドを呼び出す方法を示しています。

    // Close Button Type
    func closeButtonText(title: String?) -> NowChatConfiguration.CloseButtonType? {
      guard let title else { return nil }
      return .text(title)
    }  
      
    func closeButtonImage(name imageName: String?) -> NowChatConfiguration.CloseButtonType? {
      guard let imageName,
      let buttonImage = UIImage(named: imageName) else { return nil }
      return .image(buttonImage)	
    }


    // Create the chat UI
    func makeChatScreen() -> UIViewController? {
      guard let chatService = chatService else { return nil }
      let closePrompt = NowChatConfiguration.ClosePrompt(header: "Close Window",
        message: "Are you sure you want to close the chat window?",
        acceptButtonTitle: "Yes",
        declineButtonTitle: "No")     

      let attachmentUploadButton = NowChatConfiguration.AttachmentUploadButton(isVisible: false) // default isVisible = true         

      let chatConfiguration = NowChatConfiguration(closePrompt: closePrompt,
        disabledFeatures: [.startNewConversation],
        conversationOptions: [.forceNewConversation, .endConversationOnExit],
        uiConfiguration: NowChatConfiguration.UIConfiguration(closeButton: closeButtonImage(name: "arrow.left"), attachmentUploadButton: attachmentUploadButton))

      let result = chatService.makeChatUI(theme: CarrascoChatTheme(chatColors: ChatColors()), chatConfiguration: chatConfiguration)
             
      switch result {
        case .success(let chatViewController): 
          return chatViewController
        case .failure(let error):
          debugPrint("Chat screen creation failed with error: \(error)")
          return nil
      }
    } 

    // Start the chat session
    func startChat() {
      guard let chatService = chatService else {
        debugPrint("Chat service is invalid")
        viewState = makeViewState()
        return
      } 
      chatService.startChat { [weak self] result in
        if case .failure(let error) = result {
          debugPrint("Chat session initialization failed with error: \(error)")
          self?.resetChat()
        }
      }
     }

    // Initialize the chat service
    private func initializeChatService() {
      NowChat.makeChatService(instanceUrl: instanceUrl, delegate: self) { [weak self] result in
        guard let self = self else { return }
        switch result {
          case .success(let service):
            self.chatService = service
          case .failure(let error):
            debugPrint("Creating the chat service failed with error: \(error)") 
        } 
        self.viewState = self.makeViewState()
      }
    }


