Whatever message this page gives is out now! Go check it out!

onAddBuddyRequest

Last update:
May 18, 2026

Description

Handles incoming requests for users to add the gateway user name as one of their buddies.

Syntax

onAddBuddyRequest(CFEvent)

See also

Parameters

The method must take one parameter, a CFEvent structure with the following fields:
FieldDescription
gatewayType
Gateway type, either XMPP or SAMETIME
gatewayID
The ID of the gateway instance, as configured in ColdFusion Administrator
originatorID
The IM ID of the message originator
cfcMethod
This CFC method; by default, onAddBuddyRequest.
data.MESSAGE
The message that was sent with the request
data.SENDER
The sender's ID; identical to the originatorID field value
data.RECIPIENT
The recipient's ID, as specified in the gateway's configuration file
data.TIMESTAMP
The date and time when the message was sent

Returns

The function can optionally return a value to send a response message. The return structure must contain the following fields:
FieldDescription
command
One of the following:
  • accept - Accept the request to add you as a buddy. ColdFusion adds the user to the permit list of users that can get status information.
  • decline - Deny request to add you as a buddy. ColdFusion adds the user to the deny list of users that can get status information.
  • noact - Take no action. ColdFusion does not respond to the requestor.
buddyID
ID to which to send the message. Normally, the value of the CFEvent.data.SENDER field. Not used with the noact command.
reason
A text message describing the reason for the action. Not used with the noact command.

Example

The following example searches for the requested buddy's name in a data source and, if it finds a unique entry, adds the buddy and updates the buddy's status information in an Application scope buddyStatus structure. If it doesn't find the name, it declines the buddy. If there are multiple entries for the buddy name in the database, it tells the gateway not to respond. It logs all actions.
<cffunction name="onAddBuddyRequest"> <cfargument name="CFEvent" type="struct" required="YES"> <cfquery name="buddysearch" datasource="cfdocexamples"> SELECT IM_ID FROM Employees WHERE IM_ID = '#CFEvent.Data.SENDER#' </cfquery> <cflock scope="APPLICATION" timeout="10" type="EXCLUSIVE"> <cfscript> // If the name is in the DB once, accept; if it is missing, decline. // If it is in the DB multiple times, take no action. if (buddysearch.RecordCount IS 0) { action="decline"; reason="Invalid ID"; } else if (buddysearch.RecordCount IS 1) { action="accept"; reason="Valid ID"; //Add the buddy to the buddy status structure only if accepted. if (NOT StructKeyExists(Application, "buddyStatus")) { Application.buddyStatus=StructNew(); } if (NOT StructKeyExists(Application.buddyStatus, CFEvent.Data.SENDER)) { Application.buddyStatus[#CFEvent.Data.SENDER#]=StructNew(); } Application.buddyStatus[#CFEvent.Data.SENDER#].status= "Accepted Buddy Request"; Application.buddyStatus[#CFEvent.Data.SENDER#].timeStamp= CFEvent.Data.TIMESTAMP; Application.buddyStatus[#CFEvent.Data.SENDER#].message= CFEvent.Data.MESSAGE; } else { action="noact"; } </cfscript> </cflock> <!--- Log the request and decision information. ---> <cflog file="#CFEvent.GatewayID#Status" text="onAddBuddyRequest; SENDER: #CFEvent.Data.SENDER# MESSAGE: #CFEvent.Data.MESSAGE# TIMESTAMP: #CFEvent.Data.TIMESTAMP# ACTION: #action#"> <!--- Return the action decision. ---> <cfset retValue = structNew()> <cfset retValue.command = action> <cfset retValue.BuddyID = CFEvent.DATA.SENDER> <cfset retValue.Reason = reason> <cfreturn retValue> </cffunction>

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page