hampel/hipchat-notify 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hampel/hipchat-notify

最新稳定版本:1.1.1

Composer 安装命令:

composer require hampel/hipchat-notify

包简介

Wrapper for the Room Notification methods of the HipChat API v2 using Guzzle

README 文档

README

A HipChat API wrapper using Guzzle v6 which implements a simple room notification interface using the HipChat v2 API and is designed to be used with room authorization tokens.

By Simon Hampel.

Installation

The recommended way of installing HipChat Notifier is through Composer:

:::json
{
    "require": {
        "hampel/hipchat-notify": "~1.0"
    }
}

Configuration

To use the HipChat Notifier, you'll need to generate a room authorization token using the HipChat Group admin area.

Log in to HipChat and then go to Group admin.

Next, go to the Rooms area and find (or create) a room where notifications will be sent. Click on that room in the list to edit the settings.

On the right of the room details will be a Tokens link - click on this to see a list of any existing tokens already defined for this room.

Create a new token by entering a Label and then clicking Create.

Note that the label will be what is displayed as the user sending the message when you use the notifier, so choose something meaningful. You can always create multiple tokens for different notification sources if required.

Once you have a token, make a note of the token string - you'll need to use this whenever we ask for <room_access_token>.

You'll also need to make a note of the room API ID on the summary page, although you can retrieve this directly using the API if you wish - however it might be better to store this in a configuration setting to avoid unnecessary network calls to the API.

Usage

Messages

HipChat messages consist of four elements - the content of the message, an associated background colour displayed in the HipChat client, a boolean toggle indicating whether to notify the user about the message or not, and an indicator as to the format of the message content (text vs html).

To create messages, use the HipChat\Message class:

:::php
<?php
	use HipChat\Message;

	$message = new Message('message to be posted', Message::COLOR_GREEN, true, Message::FORMAT_TEXT);
	var_dump($message->toJson());
?>

Messages created using this class are immutable - once created, they cannot be changed without creating a new object.

For simple messages, two static helpers have been created which use the default settings (yellow background colour, don't notify).

:::php
<?php
	use HipChat\Message;

	$message = Message::createHtml('<strong>html</strong> message to be posted');
	var_dump($message->toJson());

	$message = Message::createText('text message to be posted - can use @mentions');
	var_dump($message->toJson());

?>

The JSON output of the toJson() call on a message will be in the format suitable for sending to the HipChat API.

Notifier

The notifier does all the work of communicating with the API via Guzzle.

To use the notifier, you first need to create a Guzzle Client and pass the Notifier configuration to it, which sets the base URL of the Client. Use the Notifier::getConfig() to retrieve the config array.

:::php
<?php
	use GuzzleHttp\Client;
	use HipChat\Message;
	use HipChat\Notifier;

	$client = new Client(Notifier::getConfig());

	// use the room access token created in the HipChat admin area
	$hipchat = new Notifier($client, '<room_access_token>');

	$message = new Message('message to be posted', Message::COLOR_GREEN, true, Message::FORMAT_TEXT);

	// send our message to the room with this ID
	$hipchat->send($message, '123456');
?>

Some shortcuts and tricks:

:::php
// static factory for creating a Notifier with client automatically
$hipchat = Notifier::make('<room_access_token>');

// get the room ID that this room access token is allowed to post to via the API
$roomid = $hipchat->getRoomId();

// get the full session details and use that to get the room id and room name with only a single API call
$session = $hipchat->getSession();
$roomid = $hipchat->getRoomId($session);
$roomname = $hipchat->getRoomName($session)

Exception handling:

:::php
try
{
	$hipchat->send($message, '123456');
}
catch (HipChatException $e)
{
	echo $e->getMessage();
	$response = $e->getResponse();
	if (!is_null($response))
	{
		// examine the response in more detail
	}
}

hampel/hipchat-notify 适用场景与选型建议

hampel/hipchat-notify 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 654 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 03 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「api」 「Guzzle」 「notification」 「hipchat」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 hampel/hipchat-notify 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 hampel/hipchat-notify 我们能提供哪些服务?
定制开发 / 二次开发

基于 hampel/hipchat-notify 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 654
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 16
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-03-17