SteamKit2.SteamFriends.SendChatMessage C# (CSharp) Method

SendChatMessage() public method

Sends a chat message to a friend.
public SendChatMessage ( SteamID target, EChatEntryType type, string message ) : void
target SteamID The target to send to.
type EChatEntryType The type of message to send.
message string The message to send.
return void
        public void SendChatMessage( SteamID target, EChatEntryType type, string message )
        {
            var chatMsg = new ClientMsgProtobuf<CMsgClientFriendMsg>( EMsg.ClientFriendMsg );

            chatMsg.Body.steamid = target;
            chatMsg.Body.chat_entry_type = ( int )type;
            chatMsg.Body.message = Encoding.UTF8.GetBytes( message );

            this.Client.Send( chatMsg );
        }

Usage Example

Example #1
0
		public static void Main (string[] args)
		{
			#region SteamRE Init
			AllArgs = args;
			
			//Hacking around https
			ServicePointManager.CertificatePolicy = new MainClass ();
			
			Console.ForegroundColor = ConsoleColor.Magenta;
			Console.WriteLine ("\n\tSteamBot Beta\n\tCreated by Jessecar96.\n\n");
			Console.ForegroundColor = ConsoleColor.White;
			
			
			steamClient = new SteamClient ();
			steamTrade = steamClient.GetHandler<SteamTrading>();
			SteamUser steamUser = steamClient.GetHandler<SteamUser> ();
			steamFriends = steamClient.GetHandler<SteamFriends>();
			
			steamClient.Connect ();
			#endregion
			
			
			while (true) {
				
				
				CallbackMsg msg = steamClient.WaitForCallback (true);
				
				//Console Debug
				printConsole (msg.ToString(),ConsoleColor.Blue,true);
				
				
				#region Logged Off Handler
				msg.Handle<SteamUser.LoggedOffCallback> (callback =>
				{
					printConsole("Logged Off: "+callback.Result,ConsoleColor.Red);
				});
				#endregion
				
				
				#region Steam Disconnect Handler
				msg.Handle<SteamClient.DisconnectedCallback> (callback =>
				{
					printConsole("Disconnected.",ConsoleColor.Red);
				});
				#endregion
				
				
				#region Steam Connect Handler
				
				/**
				 * --Steam Connection Callback
				 * 
				 * It's not needed to modify this section
				 */
				
				msg.Handle<SteamClient.ConnectedCallback> (callback =>
				{
					//Print Callback
					printConsole("Steam Connected Callback: "+callback.Result, ConsoleColor.Cyan);
					
					//Validate Result
					if(callback.Result==EResult.OK){
						
						//Get Steam Login Details
						printConsole("Username: "******"Password: "******"Getting Web Cookies...",ConsoleColor.Yellow);
						
						//Get Web Cookies
						SteamWeb web = new SteamWeb();
						WebCookies = web.DoLogin (user,pass);
						
						if(WebCookies!=null){
							printConsole ("SteamWeb Cookies retrived.",ConsoleColor.Green);
							//Do Login
							steamUser.LogOn (new SteamUser.LogOnDetails{
								Username = user,
								Password = pass
							});
						}else{
							printConsole ("Error while getting SteamWeb Cookies.",ConsoleColor.Red);
						}
						
					}else{
						
						//Failure
						printConsole ("Failed to Connect to steam.",ConsoleColor.Red);	
					}
					
				});
				#endregion
				
				
				#region Steam Login Handler
				//Logged in (or not)
				msg.Handle<SteamUser.LoggedOnCallback>( callback =>
        		{
					printConsole("Logged on callback: "+callback.Result, ConsoleColor.Cyan);
					
					if(callback.Result != EResult.OK){
						printConsole("Login Failed!",ConsoleColor.Red);
					}else{
						printConsole("Successfulyl Logged In!\nWelcome "+steamUser.SteamID,ConsoleColor.Green);
						
						//Set community status
						steamFriends.SetPersonaName(BotPersonaName);
						steamFriends.SetPersonaState(BotPersonaState);
					}
					
        		});
				#endregion
				
				
				#region Steam Trade Start
				/**
				 * 
				 * Steam Trading Handler
				 *  
				 */
				msg.Handle<SteamTrading.TradeStartSessionCallback>(call =>
				{
					
					//Trading
					trade = null;
					trade = new TradeSystem();
					trade.initTrade(steamUser.SteamID,call.Other,WebCookies);
					
				});
				#endregion
				
				#region Trade Requested Handler
				//Don't modify this
				msg.Handle<SteamTrading.TradeProposedCallback>( thing =>
				{
					//Trade Callback
					printConsole ("Trade Proposed Callback. Other: "+thing.Other+"\n");
					
					//Accept It
					steamTrade.RequestTrade(thing.Other);
					
				});
				#endregion

				msg.Handle<SteamFriends.PersonaStateCallback>(callback =>
                {
                    if (callback.FriendID == steamUser.SteamID)
                        return;

                    EFriendRelationship relationship = steamFriends.GetFriendRelationship(callback.FriendID);
                    if (!(relationship == EFriendRelationship.RequestRecipient))
                        return;


					if(steamFriends.GetFriendRelationship(callback.FriendID)==EFriendRelationship.PendingInvitee){
						printConsole("[Friend] Friend Request Pending: " + callback.FriendID + "(" + steamFriends.GetFriendPersonaName(callback.FriendID) + ") - Accepted", ConsoleColor.Yellow);
						steamFriends.AddFriend(callback.FriendID);
					}
                });
				
				
				#region Steam Chat Handler
				/**
				 * 
				 * Steam Chat Handler
				 * 
				 */
				msg.Handle<SteamFriends.FriendMsgCallback>(callback =>
                {
					//Type (emote or chat)
                    EChatEntryType type = callback.EntryType;
					
					if(type == EChatEntryType.ChatMsg){
						//Message is a chat message
						
						//Reply with the same message
						steamFriends.SendChatMessage(callback.Sender,EChatEntryType.ChatMsg,callback.Message);
						
						//Chat API coming soon
						
					}else if(type == EChatEntryType.Emote){
						//Message is emote
						
						//Do nothing yet
					}

                });
				#endregion
				
		
			} //end while loop
			
			
		} //end Main method
All Usage Examples Of SteamKit2.SteamFriends::SendChatMessage