Chat events
Earlier you created a conversation in the Vonage CLI and added the two users to that conversation. Conversations are how the users will communicate. You can learn more about conversations in the Conversation API documentation. Chat events, or VGConversationEvent objects, are sent using the conversation that you created, so to get chat event you will first need to join the conversation. To implement this, update the ChatViewModel class.
Add the getMemberIDIfNeeded function:
This will check if the memberID, which is generated when you join a conversation, has been set yet. If not it calls getMemberID. Create getMemberID:
This function tries to get the member ID of this user first with getConversationMember, if it fails then it will join the conversation with joinConversation which returns the member ID.
Now that that user is guaranteed to be a member of the conversation, you can get the conversation events using the client. Create a function called getConversationEvents:
getConversationEvents takes a conversation ID and VGGetConversationEventsParameters. The parameters allows you to customize how the events are returned to you. This function returns a paginated response. To learn more about pagination you can read the pagination guide. To display the events, create a helper function which turns the event objects into a display string:
The three events that are being used in this tutorial are memberJoined, memberLeft, and messageText. In the case of messageText the function uses the memberID property to determine if the message what sent by the current logged in user. This will allow the UI to pin the users sent messages to the right and received messages to the left.
The VGChatClientDelegate
The application also needs to react to events in a conversation after loading initially so you need to implement the VGChatClientDelegate didReceiveConversationEvent event.
When a new event is received it is appended to the events which is automatically published so the UI will update.
Updating the UI
Now that the ChatViewModel can retrieve and listen for new conversation events, update the view code to display them:
Now in the List, switch statement has updated to call generateDisplayText for the three different types of conversation events the tutorial is using. There is also a ProgressView for when the ChatViewModel is loading. When the view loads, onAppear is called which then calls the functions you created on the ChatViewModel.
Build and Run
Press Cmd + R to build and run again. After logging in you will see that Alice has joined the conversation:

Creating an iOS chat app
Create a iOS application that enables users to message each other