Short answer: yes to both.
Some more details now
You can use the
$command["gmsg"][$channel][] = &$module; registration to listen to a public channel, where
$channel has to be the
exact name of the public channel, including upper and lower case.
It's technical possible to output stuff to an existing public channel. But there is no pre-defined function to do it (it would be a slight variation of the send_gc() function) as bot output to public channels may lead to dire reactions on FC's side. This usually only happens if a bot is spamming the public channel, but bot owners always have to be careful.
If you want your bot to join an existing private chat group it's almost as easy. You need a module to register to
pginvite, and the handler must be similar to the one below, checking that it's a valid channel (you don't want your bot to join random channels really) and if it is accept the invite.
function pginvite($group)
{
if (strtolower($validgroup) == strtolower($group))
$this -> bot -> aoc -> privategroup_join($group);
}
The owner of the private chat (either the bot or the player) has to send you the invite. If it's a bebot it can be an !invite command or using autoinvite.
If you want to react to commands in the external channel you have to register them to the channel
extpgmsg instead of
pgmsg for the bot's group.
If you just want to parse the chat you have to register the handler
extprivgroup($pgroupname, $user, $msg).
In both cases you have to make sure in the handler that you are only parsing stuff for the correct private group.
To send to the group you can use the send_pgmsg() function, like in the following line of code:
$this -> bot -> send_pgroup($output, $mygroup);
The code above is taken from Relay_GUILD.php and just slightly modified.