Skip to content

Latest commit

 

History

History
87 lines (70 loc) · 2.69 KB

user-information.md

File metadata and controls

87 lines (70 loc) · 2.69 KB

User Information

Introduction

BotMan makes it simple to access your chatbot user information. Which user fields are available purely depend on the messaging service you use. Some services offer more information than others do. Yet you can access them using the same API with BotMan.

Retrieving User Information

BotMan has a simple way to let you retrieve user relevant information. Once you listened to a command and are in either a conversation or a message callback, you can use the getUser method on the BotMan instance.

Retrieve The User's First Name

You can access the user's first name using:

// Access user
$user = $bot->getUser();
// Access first name
$firstname = $user->getFirstName();

Retrieve The User's Last Name

You can access the user's last name using:

// Access user
$user = $bot->getUser();
// Access last name
$lastname = $user->getLastName();

Retrieve The User-ID

You can access the user ID using:

// Access user
$user = $bot->getUser();
// Access ID
$id = $user->getId();

Retrieve The Username

You can access the user Username using:

// Access user
$user = $bot->getUser();
// Access Username
$id = $user->getUsername();

Be aware that you might not receive any username data if the user hasn't set a username in their messenger settings.

Retrieve The Raw User Information

You can access also access the unprocessed raw messaging service user information that BotMan receives using:

// Access user
$user = $bot->getUser();
// Access Information
$info = $user->getInfo();

Caching User Information

BotMan will cache user information for a duration of 30 minutes by default. This is especially useful for drivers like Facebook where it takes an additional request to retrieve this information. In the BotMan config you are able to change this duration with the user_cache_time. You can also set it to zero in order to prevent BotMan from caching the user information at all.

'botman' => [
	'user_cache_time' => 30
],