# IMeetingChatController::SendChatMsgTo fails

**URL:** <https://devforum.zoom.us/t/imeetingchatcontroller-sendchatmsgto-fails/113099>\
**Category:** Meeting SDK\
**Created:** [July 4, 2024, 10:37pm UTC](https://devforum.zoom.us/t/imeetingchatcontroller-sendchatmsgto-fails/113099 "2024-07-04T22:37:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![seungkoo](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/seungkoo/32/50456_2.png) [@seungkoo](https://devforum.zoom.us/u/seungkoo)\
**Post date:** [July 4, 2024, 10:37pm UTC](https://devforum.zoom.us/t/imeetingchatcontroller-sendchatmsgto-fails/113099/1 "2024-07-04T22:37:09Z")

</div>

**zoom-meeting-sdk-linux\_x86\_64-6.0.12.5551**

**Description**

I’m currently experimenting to see if `sendChatMsg` is functioning correctly. Specifically, I’m attempting to echo the message back within `MeetingChatCtrlEvent::onChatMsgNotification`. In this function, at line `auto e = chatController_->SendChatMsgTo(msgBuilder->Build());`, `SendChatMsgTo` fails with varying error values across different runs. The chat window shows nothing, although receiving messages works fine. Any thoughts on what might be causing this?

This is the whole code block:

```auto
void MeetingChatCtrlEvent::onChatMsgNotifcation(IChatMsgInfo* chatMsg, const zchar_t* ) {
    auto msgBuilder=chatController_->GetChatMessageBuilder();
    msgBuilder->SetContent("Hello");
    msgBuilder->SetMessageType(SDKChatMessageType_To_All);
    msgBuilder->SetReceiver(0);
    msgBuilder->Build();
    auto e=chatController_->SendChatMsgTo(msgBuilder->Build());
    if(Zoom::hasError(e, "SendChatMsgTo failed:")) {
        return;
    }
}

```

---

<div class="post-metadata">

**Author:** ![chunsiong.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/chunsiong.zoom/32/35488_2.png) [@chunsiong.zoom](https://devforum.zoom.us/u/chunsiong.zoom)\
**Post date:** [July 8, 2024, 6:08am UTC](https://devforum.zoom.us/t/imeetingchatcontroller-sendchatmsgto-fails/113099/2 "2024-07-08T06:08:24Z")

</div>

@seungkoo I’ve just tried sending a chat message from the main thread and it works.

Are you trying to send a chat message from the onChatMsgNotification method itself?

```auto
	if (chatDemo) {
		IMeetingChatController* meetingchatcontroller= m_pMeetingService->GetMeetingChatController();
		meetingchatcontroller->SetEvent(new MeetingChatEventListener(&turnOnSendVideoAndAudio, &turnOffSendVideoandAudio));

		// Convert std::wstring to std::string (UTF-8)
		std::wstring wstr = L"Hello world!";
		std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
		std::string str = converter.to_bytes(wstr);

		// Ensure zchar_t is defined as char if not already defined
		typedef char zchar_t;

		char charArray[1024]; // Choose an appropriate size
		std::strncpy(charArray, str.c_str(), sizeof(charArray));

		// Ensure null-termination
		charArray[sizeof(charArray) / sizeof(charArray[0]) - 1] = '\0';

		const zchar_t* constCharArray = charArray;

		IChatMsgInfoBuilder* chatbuilder = meetingchatcontroller->GetChatMessageBuilder();
		chatbuilder->SetReceiver(0);
		chatbuilder->SetMessageType(SDKChatMessageType_To_All);
		chatbuilder->SetContent(constCharArray);
		chatbuilder->Build();
	
		meetingchatcontroller->SendChatMsgTo(chatbuilder->Build());

	}

```

---

<div class="post-metadata">

**Author:** ![seungkoo](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/seungkoo/32/50456_2.png) [@seungkoo](https://devforum.zoom.us/u/seungkoo)\
**Post date:** [July 8, 2024, 6:25pm UTC](https://devforum.zoom.us/t/imeetingchatcontroller-sendchatmsgto-fails/113099/3 "2024-07-08T18:25:14Z")

</div>

SendMsgTo was called in  
onChatMsgNotification. Verified the sendMsgTo was called in main thread. Updated zoom SDK to 6.0.10.5355. The same code worked fine. Is it possible the latest SDK would have the failure ?

---

<div class="post-metadata">

**Author:** ![chunsiong.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/chunsiong.zoom/32/35488_2.png) [@chunsiong.zoom](https://devforum.zoom.us/u/chunsiong.zoom)\
**Post date:** [July 9, 2024, 6:45am UTC](https://devforum.zoom.us/t/imeetingchatcontroller-sendchatmsgto-fails/113099/4 "2024-07-09T06:45:29Z")

</div>

@seungkoo please tag me in your response, if not I’ll not get a notification.

Are you saying sending message worked in 6.0.1 and not working in 6.1.0 when called from onChatMsgNotification?

---

<div class="post-metadata">

**Author:** ![seungkoo](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/seungkoo/32/50456_2.png) [@seungkoo](https://devforum.zoom.us/u/seungkoo)\
**Post date:** [July 9, 2024, 2:12pm UTC](https://devforum.zoom.us/t/imeetingchatcontroller-sendchatmsgto-fails/113099/5 "2024-07-09T14:12:26Z")

</div>

@chunsiong.zoom Yes that’s correct

---

<div class="post-metadata">

**Author:** ![chunsiong.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/chunsiong.zoom/32/35488_2.png) [@chunsiong.zoom](https://devforum.zoom.us/u/chunsiong.zoom)\
**Post date:** [July 10, 2024, 7:02am UTC](https://devforum.zoom.us/t/imeetingchatcontroller-sendchatmsgto-fails/113099/6 "2024-07-10T07:02:06Z")

</div>

@seungkoo

I’ve just tried this and it works, however I’m a different implementation to make sure that the sending of message will be definitely in the main thread.

```auto
//onChatMessageReceived is a helper method in the main thread, which is passed into this event listener. When there is message received on the event listener, it passes the message back into onChatMessageReceived method in the main thread.

MeetingChatEventListener::MeetingChatEventListener(void(*onChatMessageReceived)(IChatMsgInfo* chatMsg))
{
	onChatMessageReceived_ = onChatMessageReceived;
}

void MeetingChatEventListener::onChatMsgNotifcation(IChatMsgInfo* chatMsg, const zchar_t* content)
{
	std::cout<<"onChatMsgNotifcation: " << chatMsg->GetSenderDisplayName() << " says " << chatMsg->GetContent() << endl;
	if (onChatMessageReceived_)onChatMessageReceived_(chatMsg);
}

```

.  
.  
.  
//in the main thread

```auto
//callback when given receive messages
void onChatMessageReceived(IChatMsgInfo* chatMsg) {
	printf("onChatMessageReceived\n");
	IMeetingChatController* meetingchatcontroller = m_pMeetingService->GetMeetingChatController();

	// Convert std::wstring to std::string (UTF-8)
	std::wstring wstr = L"Reply to user!";
	std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
	std::string str = converter.to_bytes(wstr);

	// Ensure zchar_t is defined as char if not already defined
	typedef char zchar_t;

	char charArray[1024]; // Choose an appropriate size
	std::strncpy(charArray, str.c_str(), sizeof(charArray));

	// Ensure null-termination
	charArray[sizeof(charArray) / sizeof(charArray[0]) - 1] = '\0';

	const zchar_t* constCharArray = charArray;

	IChatMsgInfoBuilder* chatbuilder = meetingchatcontroller->GetChatMessageBuilder();
	chatbuilder->SetReceiver(0);
	chatbuilder->SetMessageType(SDKChatMessageType_To_All);
	chatbuilder->SetContent(constCharArray);
	chatbuilder->Build();

	meetingchatcontroller->SendChatMsgTo(chatbuilder->Build());

}

```

---

<div class="post-metadata">

**Author:** ![seungkoo](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/seungkoo/32/50456_2.png) [@seungkoo](https://devforum.zoom.us/u/seungkoo)\
**Post date:** [July 11, 2024, 12:43am UTC](https://devforum.zoom.us/t/imeetingchatcontroller-sendchatmsgto-fails/113099/7 "2024-07-11T00:43:07Z")

</div>

@chunsiong.zoom  
I’ve confirmed that my code executes in the main thread. Upon review, v6.0.12.5551 functions correctly for me, while v6.1.0.225 does not. However, v6.1.1.493 also works as expected. Since the most recent SDK version resolves the issues, I have no further concerns. Thank you for the follow-up.

---

<div class="post-metadata">

**Author:** ![chunsiong.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/chunsiong.zoom/32/35488_2.png) [@chunsiong.zoom](https://devforum.zoom.us/u/chunsiong.zoom)\
**Post date:** [July 12, 2024, 12:11am UTC](https://devforum.zoom.us/t/imeetingchatcontroller-sendchatmsgto-fails/113099/8 "2024-07-12T00:11:22Z")

</div>


