= IRC Component
:doctitle: IRC
:shortname: irc
:artifactid: camel-irc
:description: Send and receive messages to/from and IRC chat.
:since: 1.1
:supportlevel: Stable
:component-header: Both producer and consumer are supported
//Manually maintained attributes
:camel-spring-boot-name: irc

*Since Camel {since}*

*{component-header}*

The IRC component implements an
http://en.wikipedia.org/wiki/Internet_Relay_Chat[IRC] (Internet Relay
Chat) transport.

Maven users will need to add the following dependency to their `pom.xml`
for this component:

[source,xml]
------------------------------------------------------------
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-irc</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>
------------------------------------------------------------

// component-configure options: START

// component-configure options: END

// component options: START
include::partial$component-configure-options.adoc[]
include::partial$component-endpoint-options.adoc[]
// component options: END

// endpoint options: START

// endpoint options: END
// component headers: START
include::partial$component-endpoint-headers.adoc[]
// component headers: END

== SSL Support

=== Using the JSSE Configuration Utility

The IRC component supports SSL/TLS configuration
through the xref:manual::camel-configuration-utilities.adoc[Camel JSSE
Configuration Utility].  This utility greatly decreases the amount of
component specific code you need to write and is configurable at the
endpoint and component levels.  The following examples demonstrate how
to use the utility with the IRC component.

[[IRC-Programmaticconfigurationoftheendpoint]]
Programmatic configuration of the endpoint

[source,java]
-----------------------------------------------------------------------------------------------------------------------------------------
KeyStoreParameters ksp = new KeyStoreParameters();
ksp.setResource("/users/home/server/truststore.jks");
ksp.setPassword("keystorePassword");

TrustManagersParameters tmp = new TrustManagersParameters();
tmp.setKeyStore(ksp);

SSLContextParameters scp = new SSLContextParameters();
scp.setTrustManagers(tmp);

Registry registry = ...
registry.bind("sslContextParameters", scp);

...

from(...)
    .to("ircs://camel-prd-user@server:6669/#camel-test?nickname=camel-prd&password=password&sslContextParameters=#sslContextParameters");
-----------------------------------------------------------------------------------------------------------------------------------------

[[IRC-SpringDSLbasedconfigurationofendpoint]]
Spring DSL based configuration of endpoint

[source,xml]
----------------------------------------------------------------------------------------------------------------------------------------------
...
  <camel:sslContextParameters
      id="sslContextParameters">
    <camel:trustManagers>
      <camel:keyStore
          resource="/users/home/server/truststore.jks"
          password="keystorePassword"/>
    </camel:keyManagers>
  </camel:sslContextParameters>...
...
  <to uri="ircs://camel-prd-user@server:6669/#camel-test?nickname=camel-prd&password=password&sslContextParameters=#sslContextParameters"/>...
----------------------------------------------------------------------------------------------------------------------------------------------

=== Using the legacy basic configuration options

You can also connect to an SSL enabled IRC server, as follows:

[source,java]
--------------------------------------------------
ircs:host[:port]/#room?username=user&password=pass
--------------------------------------------------

By default, the IRC transport uses
http://moepii.sourceforge.net/irclib/javadoc/org/schwering/irc/lib/ssl/SSLDefaultTrustManager.html[SSLDefaultTrustManager].
If you need to provide your own custom trust manager, use the
`trustManager` parameter as follows:

[source,java]
----------------------------------------------------------------------------------------------
ircs:host[:port]/#room?username=user&password=pass&trustManager=#referenceToMyTrustManagerBean
----------------------------------------------------------------------------------------------

== Using keys

Some irc rooms requires you to provide a key to be able to join that
channel. The key is just a secret word.

For example we join 3 channels where as only channel 1 and 3 uses a key.

[source,java]
-----------------------------------------------------------------------------
irc:nick@irc.server.org?channels=#chan1,#chan2,#chan3&keys=chan1Key,,chan3key
-----------------------------------------------------------------------------

== Getting a list of users of the channel

Using the `namesOnJoin` option one can invoke the IRC-`NAMES` command after the component has joined a channel. 
The server will reply with `irc.num = 353`. So in order to process the result the property `onReply` has to be `true`.
Furthermore one has to filter the `onReply` exchanges in order to get the names.

For example we want to get all exchanges that contain the usernames of the channel:

[source,java]
-----------------------------------------------------------------------------
from("ircs:nick@myserver:1234/#mychannelname?namesOnJoin=true&onReply=true")
	.choice()
		.when(header("irc.messageType").isEqualToIgnoreCase("REPLY"))
			.filter(header("irc.num").isEqualTo("353"))
			.to("mock:result").stop();
-----------------------------------------------------------------------------

== Sending to different channel or a person

If you need to send messages to a different channel (or a person) which is not defined on IRC endpoint, you can specify a different destination in a message header.

You can specify the destination in the following header:

[width="100%",cols="10%,10%,80%",options="header",]
|=====================================================================
|Header |Type |Description
|`irc.sendTo` |`String` |The channel (or the person) name.
|=====================================================================


include::spring-boot:partial$starter.adoc[]
