How to send a message in PHP?

In order to send a message in your PHP code please use the function below.

if (class_exists('WiseChatContainer', false)) {
	function addWiseChatProMessage($channelName, $userId, $message) {
		$messagesService = WiseChatContainer::get('services/WiseChatMessagesService');
		$usersDao = WiseChatContainer::get('dao/user/WiseChatUsersDAO');
		$channelsDao = WiseChatContainer::get('dao/WiseChatChannelsDAO');
		$user = $usersDao->getLatestByWordPressId($userId);
		if (!$user) {
			throw new \Exception('User never visited the chat: '.$userId);
		$channel = $channelsDao->getByName($channelName);
		if (!$channel) {
			throw new \Exception('Channel does not exist: '.$channelName);
		$messagesService->addMessage($user, $channel, $message, array());
	// 'global' - The name of the channel, it must exist before executing this function
	// 1 - WordPress user ID, the user must visit the chat at least once before executing this function
	addWiseChatProMessage('global', 1, 'Test message');

Back to FAQ