tealorca/laravel-freshchat

Freshchat Web 小部件用于 Laravel

v0.0.2 2021-03-20 09:17 UTC

This package is auto-updated.

Last update: 2024-09-20 19:04:29 UTC


README

Latest Version on Packagist Total Downloads

安装

您可以通过 composer 安装此包

composer require tealorca/laravel-freshchat

此包将自动注册服务提供者。

接下来,通过在 body 标签末尾添加 Blade 指令 @laravelFreshchat 将聊天小部件包含到 blade 布局代码中。

<body>
    ...
    ...
    @laravelFreshchat
</body>
</html>

接下来,您需要发布 freshchat 配置文件

php artisan vendor:publish --provider="TealOrca\LaravelFreshchat\LaravelFreshchatServiceProvider" --tag="config"

这是要发布的默认配置文件内容,将作为 config/laravel-freshchat.php 发布

/*
 * Freshchat Configurations
 */
return [

    /*
     * Freshchat's Web Messenger Token.
     *
     * You can see that on Web Messenger Settings page of Freshchat Portal.
     */
    'token'      => env('FRESHCHAT_TOKEN', null),

    /*
     * Freshchat's Web Messenger Host Value. ( it would be different based on your data region)
     *
     * Few examples:
     *
     *	https://wchat.freshchat.com
     *	https://wchat.in.freshchat.com
     *
     * You can see that on Web Messenger Settings page of Freshchat Portal.
     */
    'host'       => env('FRESHCHAT_HOST', 'https://wchat.freshchat.com'),
];

一旦您在 .env 文件中添加了 FRESHCHAT_TOKENFRESHCHAT_HOST 值,您就可以在网页上看到小部件了。

显示的小部件将被视为一个 匿名用户 窗口。

有关更多详细信息,请参阅 Freshchat 的 Web SDK 文档

配置登录用户

ChatUser 特性添加到您的用户模型中

要使当前认证用户被视为 Freshchat 用户,只需将 TealOrca\LaravelFreshchat\Traits\ChatUser 特性添加到用户认证模型中。

use TealOrca\LaravelFreshchat\Traits\ChatUser;

class User extends Model {

    use ChatUser;

	/**
     * Specify the column name for Freshchat Restore Id
     */
    protected $freshchatRestoreId = '<<the column name you created for storing the Freshchat restoreId>>';

    /**
     * Specify the value for Freshchat External Id
     *
     * @return string
     */
    public function chatUserExternalId()
    {
        return $this->email; // using the user's email as the external id
    }

    /**
     * Specify the properties
     *
     * @return array
     */
    public function chatUserProperties() {

        return [
            'firstName' => 'first_name', ////// '<< Property Name for Freshchat >>' => '<< column name on the users table >>',
            'lastName' => 'last_name',
            'email' => 'email',
            'phone' => 'phone_no',
            'phoneCountryCode' => 'phone_country_code',
        ];
    }
}

将恢复 ID 列添加到您的用户表中

php artisan make:migration add_freshchat_restore_id_to_users_table --table=users
class AddFreshchatRestoreIdToUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {

            if (!Schema::hasColumn('users', 'freshchat_restore_id')) {
                Schema::table('users', function (Blueprint $table) {
                    $table->string('freshchat_restore_id')->nullable();
                });
            }

        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('users', function (Blueprint $table) {

            if (Schema::hasColumn('users', 'freshchat_restore_id')) {
                $table->dropColumn('freshchat_restore_id');
            }
        });
    }
}

变更日志

请参阅 CHANGELOG 了解最近更改了什么。

贡献

请参阅 CONTRIBUTING 了解详情。

安全

如果您发现任何与安全相关的问题,请通过电子邮件 danielfelix1995@gmail.com 而不是使用问题跟踪器。

鸣谢

许可

MIT 许可证(MIT)。有关更多信息,请参阅 许可文件