Skip to content

Commit 9aa5e5b

Browse files
add usage
1 parent 2bfc348 commit 9aa5e5b

File tree

12 files changed

+277
-0
lines changed

12 files changed

+277
-0
lines changed

Diff for: .github/CODEOWNERS

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#
2+
# https://help.github.com/articles/about-codeowners/
3+
#
4+
5+
* @wechaty/php

Diff for: .github/workflows/php.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# For more information see: https://docs.github.com/en/actions/getting-started-with-github-actions
2+
3+
name: PHP CI
4+
5+
on:
6+
push:
7+
branches: [ master ]
8+
pull_request:
9+
branches: [ master ]
10+
11+
jobs:
12+
build:
13+
14+
runs-on: ${{ matrix.operating-system }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
operating-system: [ubuntu-20.04]
19+
php-versions: ['7.4', '8.0']
20+
env:
21+
extensions: xml, opcache, xdebug, pcov, grpc, protobuf
22+
key: cache-v3
23+
24+
steps:
25+
- name: Checkout
26+
- uses: actions/checkout@v2
27+
- name: Setup PHP with extensions and custom config
28+
run: node dist/index.js
29+
env:
30+
php-version: ${{ matrix.php-versions }}
31+
extensions: ${{ env.extensions }}
32+
ini-values: post_max_size=256M, short_open_tag=On, date.timezone=Asia/Shanghai
33+
- name: Testing PHP version
34+
run: |
35+
php -v
36+
php -r "if(strpos(phpversion(), '${{ matrix.php-versions }}') === false) {throw new Exception('Wrong PHP version Installed');}"
37+
- name: Testing Composer version
38+
run: |
39+
composer -V
40+
php -r "if(strpos(@exec('composer -V'), 'Composer version') === false) {throw new Exception('Composer not found');}"
41+
- name: install with composer
42+
run: composer install

Diff for: .gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.idea
2+
.DS_Store
3+
4+
/vendor/*

Diff for: .gitpod.Dockerfile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM gitpod/workspace-full
2+
3+
USER gitpod
4+
5+
RUN sudo pecl channel-update pecl.php.net && \
6+
sudo pecl install grpc && \
7+
sudo pecl install protobuf
8+
9+
# Install custom tools, runtime, etc. using apt-get
10+
# For example, the command below would install "bastet" - a command line tetris clone:
11+
#
12+
# RUN sudo apt-get -q update && # sudo apt-get install -yq bastet && # sudo rm -rf /var/lib/apt/lists/*
13+
#
14+
# More information: https://www.gitpod.io/docs/config-docker/

Diff for: .gitpod.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
tasks:
2+
- init: make
3+
image:
4+
file: .gitpod.Dockerfile

Diff for: .vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files.exclude": {
3+
"**/.idea": true
4+
}
5+
}

Diff for: Makefile

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.PHONY: all
2+
all: install bot
3+
4+
.PHONY: install
5+
install:
6+
composer install
7+
8+
.PHONY: bot
9+
bot:
10+
php examples/ding-dong-bot.php
11+
12+
.PHONY: clean
13+
clean:
14+
rm -rf vendor/*
15+
16+
.PHONY: version
17+
version:
18+
@newVersion=$$(awk -F. '{print $$1"."$$2"."$$3+1}' < VERSION) \
19+
&& echo $${newVersion} > VERSION \
20+
&& git add VERSION \
21+
&& git commit -m "$${newVersion}" > /dev/null \
22+
&& git tag "v$${newVersion}" \
23+
&& echo "Bumped version to $${newVersion}"

Diff for: NOTICE

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
PHP Wechaty Chatbot SDK
2+
Copyright 2020 Wechaty Contributors.
3+
4+
This product includes software developed at
5+
The Wechaty Organization (https://github.com/wechaty).

Diff for: README.md

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# php-wechaty-getting-started [![PHP Version](https://img.shields.io/maven-central/v/io.github.wechaty/wechaty?label=PHP)](https://packagist.org/packages/wechaty/php-wechaty) [![PHP CI](https://github.com/wechaty/php-wechaty-getting-started/workflows/PHP%20CI/badge.svg)](https://github.com/wechaty/php-wechaty-getting-started/actions?query=workflow%3A%22PHP+CI%22)
2+
3+
[![PHP Wechaty](https://wechaty.github.io/php-wechaty/images/php-wechaty.png)](https://github.com/wechaty/php-wechaty-getting-started)
4+
5+
PHP Wechaty Starter Project Template that Works Out-of-the-Box
6+
7+
[![Wechaty in PHP](https://img.shields.io/badge/Wechaty-PHP-blue)](https://github.com/wechaty/php-wechaty)
8+
9+
## Connecting Chatbots
10+
11+
[![Powered by Wechaty](https://img.shields.io/badge/Powered%20By-Wechaty-brightgreen.svg)](https://github.com/Wechaty/wechaty)
12+
[![PHP Version](https://img.shields.io/maven-central/v/io.github.wechaty/wechaty?label=PHP)](https://packagist.org/packages/wechaty/php-wechaty)
13+
14+
Wechaty is a RPA SDK for Wechat **Individual** Account that can help you create a chatbot in 6 lines of Java.
15+
16+
## The World's Shortest Java ChatBot: 8 lines of Code
17+
18+
```php
19+
$wechaty = \IO\Github\Wechaty\Wechaty::getInstance($token, $endPoint);
20+
$wechaty->onScan(function($qrcode, $status, $data) {
21+
$qr = \IO\Github\Wechaty\Util\QrcodeUtils::getQr($qrcode);
22+
echo "$qr\n\nOnline Image: https://wechaty.github.io/qrcode/$qrcode\n";
23+
})->onLogin(function(\IO\Github\Wechaty\User\ContactSelf $user) {
24+
})->onMessage(function(\IO\Github\Wechaty\User\Message $message) {
25+
$message->say("hello from PHP7.4");
26+
})->start();
27+
```
28+
29+
## Usage
30+
31+
### Install
32+
33+
```sh
34+
# Install make sure php is 7.4+
35+
sudo yum install php-pecl-grpc
36+
sudo yum install php-pecl-protobuf
37+
# curl -sS https://getcomposer.org/installer | php
38+
php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
39+
php composer-setup.php
40+
php -r "unlink('composer-setup.php');"
41+
mv composer.phar /usr/local/bin/composer
42+
43+
make install
44+
```
45+
46+
### Run
47+
48+
```sh
49+
export WECHATY_PUPPET_HOSTIE_TOKEN=your_token_at_here
50+
51+
make bot
52+
```
53+
54+
## Wechaty Getting Started in Multiple Languages
55+
56+
- [TypeScript Wechaty Getting Started](https://github.com/wechaty/wechaty-getting-started)
57+
- [Python Wechaty Getting Started](https://github.com/wechaty/python-wechaty-getting-started)
58+
- [Java Wechaty Getting Started](https://github.com/wechaty/java-wechaty-getting-started)
59+
- [Go Wechaty Getting Started](https://github.com/wechaty/go-wechaty-getting-started)
60+
61+
## Badge
62+
63+
[![Wechaty in PHP](https://img.shields.io/badge/Wechaty-PHP-blue)](https://github.com/wechaty/php-wechaty)
64+
65+
```md
66+
[![Wechaty in PHP](https://img.shields.io/badge/Wechaty-PHP-blue)](https://github.com/wechaty/php-wechaty)
67+
```
68+
69+
## Maintainers
70+
71+
[@wechaty/php](https://github.com/orgs/wechaty/teams/php/members)
72+
73+
## Copyright & License
74+
75+
- Code & Docs © 2020 Wechaty Contributors <https://github.com/wechaty>
76+
- Code released under the Apache-2.0 License
77+
- Docs released under Creative Commons

Diff for: VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.1

Diff for: composer.json

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "wechaty/php-wechaty-getting-started",
3+
"type": "template",
4+
"description": "PHP Wechaty Starter Project Template that Works Out-of-the-Box.",
5+
"keywords": [
6+
"template",
7+
"autoload"
8+
],
9+
"homepage": "https://github.com/wechaty/php-wechaty-getting-started",
10+
"license": "Apache-2.0",
11+
"version": "v0.0.1",
12+
"authors": [
13+
{
14+
"name": "Chunsheng Zhang",
15+
"email": "[email protected]",
16+
"homepage": "https://www.luomor.com/"
17+
}
18+
],
19+
"require": {
20+
"php": "^7.4 || ^8.0",
21+
"wechaty/php-wechaty": "^v0.0.1"
22+
},
23+
"require-dev": {
24+
25+
},
26+
"config": {
27+
28+
},
29+
"extra": {
30+
31+
},
32+
"autoload": {
33+
"psr-4": {
34+
35+
}
36+
},
37+
"autoload-dev": {
38+
"psr-4": {
39+
"Tests\\": "examples/"
40+
}
41+
},
42+
"scripts": {
43+
44+
},
45+
"support": {
46+
"issues": "https://github.com/wechaty/php-wechaty-getting-started/issues"
47+
}
48+
}

Diff for: examples/ding-dong-bot.php

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: peterzhang
5+
* Date: 2020/7/22
6+
* Time: 1:53 PM
7+
*/
8+
9+
use IO\Github\Wechaty\Puppet\FileBox\FileBox;
10+
use IO\Github\Wechaty\User\ContactSelf;
11+
use IO\Github\Wechaty\User\MiniProgram;
12+
use IO\Github\Wechaty\User\UrlLink;
13+
14+
define("ROOT", dirname(__DIR__));
15+
// DEBUG should create dir use command sudo mkdir /var/log/wechaty && sudo chmod 777 /var/log/wechaty
16+
define("DEBUG", 1);
17+
18+
require ROOT . '/vendor/autoload.php';
19+
20+
// change dir
21+
// \IO\Github\Wechaty\Util\Logger::$_LOGGER_DIR = "/tmp/";
22+
23+
$token = getenv("WECHATY_PUPPET_HOSTIE_TOKEN");
24+
$endPoint = getenv("WECHATY_PUPPET_HOSTIE_ENDPOINT");
25+
$wechaty = \IO\Github\Wechaty\Wechaty::getInstance($token, $endPoint);
26+
$wechaty->onScan(function($qrcode, $status, $data) {
27+
if($status == 3) {
28+
echo "SCAN_STATUS_CONFIRMED\n";
29+
} else {
30+
$qr = \IO\Github\Wechaty\Util\QrcodeUtils::getQr($qrcode);
31+
echo "$qr\n\nOnline Image: https://wechaty.github.io/qrcode/$qrcode\n";
32+
}
33+
})->onLogin(function(ContactSelf $user) {
34+
echo "login user id " . $user->getId() . "\n";
35+
echo "login user name " . $user->getPayload()->name . "\n";
36+
})->onMessage(function(\IO\Github\Wechaty\User\Message $message) use ($wechaty) {
37+
$name = $message->from()->getPayload()->name;
38+
$text = $message->getPayload()->text;
39+
echo "message from user name $name : $text\n";
40+
if($text == "ding") {
41+
$message->say("dong");
42+
} else if($text == "_stop_") {
43+
$wechaty->stop();
44+
} else {
45+
$message->say("hello $name from php-wechaty");
46+
}
47+
})->onHeartBeat(function($data) use ($wechaty) {
48+
echo $data . "\n";
49+
})->start();

0 commit comments

Comments
 (0)