Chat::iFly - An interface to the iFlyChat service.
use Chat::iFly; my $chat = Chat::iFly->new( api_key => 'afsdadfafdsadfsafsd', static_asset_base_uri => '//www.myserver.com/ifly', ajax_uri => '//www.myserver.com/chat/login' ); my $user = { id => 4321, name => 'Joe Blow', avatar_uri => '//www.myserver.com/uploads/joe.blow.avatar.jpg', profile_uri => '//www.myserver.com/users/4321', }; my $html_to_inline_into_page = $chat->render_html($user); my $response_to_chat_login = $chat->render_ajax($user);
A wrapper needed to authenticate to iflychat.com.
You'll need to go here https://iflychat.com/iflyapi/index and register for an API Key. You'll specify that using api_key passed to the constructor.
api_key
You'll need to copy the public folder from this distribution onto your web server somewhere. You'll specify where that is using the static_asset_base_uri passed tot he constructor.
public
static_asset_base_uri
You'll need to build 2 things into your web server:
You'll need to inline the result of render_html into any web page where you want the chat to appear.
render_html
You'll need to set up an ajax method in your app that returns the result of render_ajax. You'll pass the URL where that can be found into the constructor using ajax_uri.
render_ajax
ajax_uri
And finally you need to call update_settings to tell the iFly servers what your settings are.
update_settings
The following methods are available.
Constructor.
A hash of parameters.
Required. The key generated on the iFly Chat Dashboard.
Required. The URL where you have installed the static files found in the public folder of the Chat::iFly github repository.
Required. The URL where you have installed the response to the render_ajax method.
Defaults to 2. Must be 1 or 2. Minimize online user list by default. 2 means Yes. 1 means No.
2
Defaults to 1. Must be 1 or 2. Show search bar in online user list. 1 means Yes. 2 means No.
1
Defaults to #222222. Choose the color of the top bar in the chat.
#222222
Defaults to #FFFFFF. Choose the color of the text in top bar in the chat.
#FFFFFF
Defaults to #222222. Choose the color of the text in the chat.
Defaults to Chat. This is the text that will appear in header of chat list.
Chat
Defaults to Chat with us. The label for Start Chat button, which when clicked upon will launch chat.
Chat with us
Defaults to Support. This is the text that will appear as header of chat box.
Support
Defaults to Support Team. Name of your team or company which the visitors will see in the chat box.
Support Team
Defaults to Ask us anything.... Your team/company tagline.
Ask us anything...
Defaults to 1. Must be 1 or 2. 1 means that the auto greeting is enabled.
Defaults to Hi there! Welcome to our website. Let us know if you have any query!. This is the text of an auto greeting message which will be displayed to visitors.
Hi there! Welcome to our website. Let us know if you have any query!
Defaults to 1. The delay, in seconds, after which the first time visitors will be shown auto greeting message.
Defaults to Leave Message. The label for Leave Message button, which when clicked upon will offline form.
Leave Message
Defaults to Hello there. We are currently offline. Please leave us a message. Thanks.. This is the description shown in Support Chat Offline window.
Hello there. We are currently offline. Please leave us a message. Thanks.
Defaults to Message. This is the label for the Message textarea in Support Chat Offline window.
Message
Defaults to Contact Details. This is the label for the <i>Contact Details</i> textarea in Support Chat Offline window.
Contact Details
Defaults to Send Message. This is the label for the Send Button textarea in Support Chat Offline window.
Send Message
Enter all email addresses (separated by comma) to which notification should be sent when a user leaves a message via Offline Form.
Defaults to Go Online. Set this to change the label of the status of a user to an online state.
Go Online
Defaults to Go Idle. Set this to change the label of the status of a user to an idle state.
Go Idle
Defaults to New chat message!. Set this to change the label of the notification when a new chat message has come in.
New chat message!
Defaults to Public Chatroom. This is the text that will appear in header of public chatroom.
Public Chatroom
Defaults to 1. Must be 1 or 2. 1 means that the public chatroom is enabled.
Defaults to light. Must be light or dark. Other options may exist in the future, or you could create your own.
light
dark
Defaults to 1. Must be 1 or 2. When set to 1 the chat will play a notification sound when a message is posted.
Defaults to static_asset_base_uri + /swf/sound.swf. The URL to where the sound player is stored.
/swf/sound.swf
Defaults to static_asset_base_uri + /wav/notification.mp3. The URL to where the notification sound is stored.
/wav/notification.mp3
Defaults to 1. Must be 1 or 2. When set to 1 users will have access to emoticons.
Defaults to static_asset_base_uri + /smileys/very_emotional_emoticons-png/png-32x32/. The URL to where the emoticons are stored.
/smileys/very_emotional_emoticons-png/png-32x32/
Defaults to 1. Must be 1 or 2. When set to 1 chat messages will be logged to the user's inbox. See get_message_inbox.
get_message_inbox
Defaults to Guest. A prefix that will be applied to anonymous generated usernames.
Guest
Perl boolean. When true guest names will be pulled from local_anonymous_names, which is faster than consulting the remote server. When false a list of names will be polled from the iFly server.
local_anonymous_names
An array reference of local names. There's a default list of 50 or so English sounding names. For use with use_local_anonymous_names.
use_local_anonymous_names
Defaults to 1. Must be 1. Whether to use stop_word_list to filter user posts. 1 means don't filter. 2 means filter in public chat room. 3 means filter in private chats. 4 means filter in all chats.
stop_word_list
A comma separated string of "bad" words. A list of about a hundred defaults this list.
Defaults to 1. Must be 1, 2, 3, or 4. 1 means don't block links. 2 means block in public chatroom. 3 menas block in private chat rooms. 4 means block in all chats.
Defaults to 2. Must be 1 or 2. 1 means apply stop_links only to anonymous users. 2 means apply stop_links to all users.
stop_links
Defaults to 1. Must be 1 or 2. When set to 1 images and video links will be rendered inline in the chat.
Defaults to 1. Must be 1 or 2. When set to 1 users can set their name color.
Defaults to 1. Must be 1, 2, or 3. Allow users to delete messages selectively when in private conversation. 1 means allow all users. 2 means allow moderators. 3 means do not allow.
Defaults to 1. Must be 1, 2, or 3. Allow users to clear all messages in a room. 1 means allow all users. 2 means allow moderators. 3 means do not allow.
Defaults to 2. Must be 1 or 2. When set to 2 the chat will be in "Community" mode, which means users can talk to each other. When set to 1 the chat is in "Support" mode and users can only talk to admins.
Defaults to 1. Must be 1 or 2. 1 means to enable user avatars.
Determine how to render the list when no users are online. Defaults to:
<div class="item-list"><ul><li class="drupalchatnousers even first last">No users online</li></ul></div>
The base URI of the service you're interacting with. Defaults to https://api.iflychat.com.
https://api.iflychat.com
The port you're interacting with for iFly. Defaults to 443.
443
A HTTP::Thin object.
This method renders the HTML you need to inline into your web page to configure the chat.
A hash reference containing a user as defined in get_key. However, you only need to pass this in if the user is registered with the site, not for anonymous users.
get_key
This method renders the response that will log the user into the chat.
NOTE: For best performance and to ensure persistent user names for anonymous users you should cache the result of this method in your session management system.
Required. A hash reference containing a user definition. For an anonymous user call generate_anonymous_user. Otherwise define the user as described in the get_key method.
generate_anonymous_user
This method is called by render_html to generate the list of settings to initialize the chat. There should proably not be a reason for you to call it yourself.
Generates an anonymous user hash reference to be used with get_key or render_ajax.
Retrieves a random name from the iFly servers for anonymous users. This is called by generate_anonymous_user and probably doesn't need to be used by you.
This method is used to essentially log a user into the chat system. It generates a key that is used by the javascript to communicate back to the chat server.
A hash reference containing the definition of a user. If this is an anonymous user then generate it using generate_anonymous_user.
The unique id of the user. It can be any alphanumeric string, and cannot contain special characters or start with a number. I recommend hex encoding your string and then prepending "ifly" on it to create a string that fits their ID scheme.
The name or username of the user.
Defaults to 0. Can be set to 1 if the user should have chat admin privileges.
Defaults to normal. Ignored entirely if is_admin is set to 1. You can also pass in a hash of custom roles (not admin or normal) that will be used as CSS classes for styling. For example:
normal
is_admin
{ 1 => 'cool', 2 => 'slick', }
A URI string that references a picture used to identify the user.
A URI string that will link other users to this user's profile on the web site.
This allows you to set up buddy lists within the chat. It is a hash reference taking the form of:
{ 1 => { name => 'friend', plural => 'friends', valid_uids => ['user_id_1', 'user_id_5', 'user_id_3'] }, 2 => { name => 'co-worker', plural => 'co-workers', valid_uids => ['user_id_3', 'user_id_4', 'user_id_2'] }, }
Updates the iFly servers with all the configured settings you passed into the constructor of this object. This must be called when you first start using this module, and also each time that you make changes to your settings.
Returns a hash reference of a message thread between two users.
Required. The unique user id of the first user in the discussion.
Required. The unique user id of the second user in the discussion.
Returns a hash reference containing the messages in the user's inbox.
The unique user id of the user who's inbox you want to retrieve.
Performs a GET request, which is used for reading data from the service.
GET
The path to the REST interface you wish to call.
A hash reference of parameters you wish to pass to the web service.
Performs a POST request, which is used for creating data in the service.
POST
HTTP::Thin Ouch HTTP::Request::Common JSON URI Moo
http://github.com/rizen/Chat-iFly
http://github.com/rizen/Chat-iFly/issues
JT Smith <jt_at_plainblack_dot_com>
This module is Copyright 2014 Plain Black Corporation. It is distributed under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head2'
To install Chat::iFly, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Chat::iFly
CPAN shell
perl -MCPAN -e shell install Chat::iFly
For more information on module installation, please visit the detailed CPAN module installation guide.