.netvb.netskype4com

How to create moderated chat, then add contact to the chat created


as seen in the title, I am trying to create a moderated chat and then add a contact to the chat created.

I tried this to add someone to a group chat (something like this):

For Each chat As Chat In Skypattach.BookmarkedChats
If chat.Name = "#my-skype/$baf1ad******" Then
    msg.Chat.SendMessage("Please wait while we add you!)
    chat.SendMessage("/add " & "contact-to-add")
End If
Next

But I need to specify the chat name, so that doesn't work for now. I got an idea I don't know how to do, and don't know if its possible, but also is there a way to create the moderated chat, then get the chat name of the chat created? That could fix my problem... If there's any fix to my problem please tell me. Thanks for your time.


Solution

  • I'm suprised that the line chat.SendMessage("/add " & "contact-to-add") works in the first place, as I get errors when I use it. So instead, I used a subroutine to add the new member(s) in via a UserCollection object. When you want to add new members, add to the UserCollection, and then pass that to the AddMembers() subroutine.

    As for the chat name itself, you don't need it. If you create the chat on the spot, you assign it to a Chat variable.

    Imports SKYPE4COMLib
    
    
    Public Class Form1
    
    Dim skype As Skype
    Dim uc As UserCollection
    Dim chat As Chat
    
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        skype = New Skype()
        skype.Attach(7, True)
    End Sub
    
    
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        uc = New UserCollection()    'Hold the users in a UserCollection obj
        uc.Add(skype.User("echo123"))
        uc.Add(skype.User("otherperson_123123123123121625"))
    
        chat = skype.CreateChatMultiple(uc)  'Create the chat with the 2 users
        chat.OpenWindow()
        chat.Topic = "test"
        chat.SendMessage("test")
    End Sub
    
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        'CHECK TO MAKE SURE YOU DON'T TRY AND ADD SAME PERSON TWICE!
        'For some reason, attempting to do so causes errors.
        For Each r As User In uc
            If TextBox1.Text = r.Handle Then
                Return
            End If
        Next
        skype.SendMessage(TextBox1.Text, "Please wait while we add you!")
        uc.Add(skype.User(TextBox1.Text))
        chat.AddMembers(uc)
    End Sub
    End Class
    

    I hope you that this answers your question and is useful to you.