メニュー

Expand
ページを評価:

Chatの基本

Programmable Chat is a cloud-based chat product which provides a number of client SDKs and a REST API for use in integrating Chat capabilities into applications and websites.

データ型

Programmable Chat has several core data types or objects which you will interact with:

Services

チャットサービスはチャットのデプロイメントにおいて全チャンネル、メッセージ、ユーザー、そして他のリソースを包含している場所です。 サービスは完全に分離されており、アカウント内に多数のアカウントが存在しても、サービス同士が重複または競合することはありません。

Note: To interact with Chat, you will need to create a Chat Service instance for your SDKs to connect to, and for your backend to be able to control via REST. You can create and configure Chat Service instances in the following places and ways:

ユーザー管理

Programmable Chat is a user-centric system, and each unique identity connecting to a Chat Service will create a User record. You can read more about user identities and access tokens as well as "active users."

役割

Within a Chat Service, Users can interact in different ways with the Service itself as well as with Channels, Messages, Users, and Members. A User's Role determines their permissions within a Service and various Channels.

Channels

チャンネルはサービス内での全チャットアクティビティーの中心です。 チャンネルのメンバーはチャンネルにメッセージを送信し、それはチャンネルの他のメンバーに配信されます。 チャンネルはprivateまたはpublicになります。

プライベートチャンネルは追加または招待されたユーザー以外には見えません。 プライベートチャンネルのメンバーは十分な権限を持つメンバー、または開発者のビジネスロジックによる制御におけるREST API経由でのみが追加できます。

公開チャンネルはサービス上のいかなるユーザーでも閲覧と参加が可能です。

メンバー

A User within a Service can interact with Channels as a Member. Members have an assigned Role within a given Channel that dictates what the Member can do within that Channel.

Messages

All chat Messages exist within a Service as part of a Channel. Messages are stored in order, and all Members of a Channel can access Messages and create new ones. Note that Member permissions can be modified to limit the actions and data allowed within a Channel via their assigned Role.

Messages can also be edited and removed (subject to Role permissions).

REST API

The Chat REST API is used by your backend services and is intended for system usage. The API can be used to orchestrate the usage of Programmable Chat - such as creating a private Channel and adding a customer support agent User as a Member along with the customer User.

Your backend logic can control virtually every aspect of a Service including creating Channels, adding or removing Users and Members, sending Messages and more.

SDK

The Programmable Chat SDKs have many shared fundamentals which are important for you to understand to ensure best practices and proper usage. This guide introduces these fundamentals and aims to provide code samples for each SDK.

一人称クライアントSDK

Twilio's Chat SDKs are used to build 1st person chat experiences in mobile and web applications. These experiences are designed to be user-centric, authenticated and identified by your backend.

All access and interactions from the Chat SDK client endpoints happen in the context of this user identity interacting with Channels and Messages on the Chat Service. It is therefore important for your application to perform any necessary authentication or authorization of the User before generating an Access Token for their identity .

SDKの接続性

The SDKs interact with the Chat Service over a websocket connection which is established and maintained by the SDK. Communication with the Chat Service is in real time and is bidirectional in nature. The following protocols and hostnames are used to communicate with Twilio's cloud. If necessary, use this information to configure your firewall to enable communication with Twilio.

リージョン ID 所在地 Host Name Port and Protocol
us1 米国東海岸(バージニア) wss://tsock.us1.twilio.com 443 WSS (websocket over TLS)
us1 米国東海岸(バージニア) https://media.us1.twilio.com 443 HTTPS (HTTP over TLS)
us1 米国東海岸(バージニア) https://mcs.us1.twilio.com 443 HTTPS (HTTP over TLS)

Unfortunately, at this moment it is not possible to use static IP addresses due to the nature of the load balancing setup. In case an allow-list is required, it is still possible to enable a larger range of Amazon Web Service IP addresses.

アクセストークン

To interact with a Chat Service from an SDK client, a valid Access Token is needed. This Access Token is generated by your backend using the relevant Twilio Helper Library and is cryptographically signed to ensure the contents are trusted by the Chat Service.

You will also need to implement the Token refresh logic if your client uses Access Tokens that are shorter lived than your Chat Client sessions. The optional AccessManager helper is available for all platforms and can assist with this.

アクセストークンのの生成とトークンのライフサイクルの管理方法iについてもお読みください。

非同期のやりとり

The Chat SDKs all follow an asynchronous model of interaction with the Chat Service. This means that commands from the SDK clients do not block synchronously while waiting for the final result of the command (although they will receive a response from the Service upon command acceptance). Instead, event handlers (callback handlers/listeners) must be implemented on the client side to receive and process the asynchronous responses from the service.

Each SDK has a particular mechanism for asynchronous event handlers:

  1. JS: プロミス
  2. iOS: デリゲートとブロック
  3. Android: リスナー

Examples of how these work in various places within the Chat SDKs are found in the more specific guides which follow.

次: SDKの初期化

ページを評価:

ヘルプが必要ですか?

誰しもが一度は考える「コーディングって難しい」。そんな時は、お問い合わせフォームから質問してください。 または、Stack Overflow でTwilioタグのついた情報から欲しいものを探してみましょう。

        
        
        

        フィードバックくださりありがとうございます!

        We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

        Sending your feedback...
        🎉 Thank you for your feedback!
        Something went wrong. Please try again.

        Thanks for your feedback!

        Refer us and get $10 in 3 simple steps!

        ステップ1

        Get link

        Get a free personal referral link here

        ステップ2:

        Give $10

        Your user signs up and upgrade using link

        ステップ3

        Get $10

        1,250 free SMSes
        OR 1,000 free voice mins
        OR 12,000 chats
        OR more