Skip to content

Commit f1917e3

Browse files
committed
Rename package and modify related code. Rewrite README.md. Fix simple-server-echo (for python2 and 3 issue)
1 parent a046454 commit f1917e3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+133
-83
lines changed

MANIFEST.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
include LICENSE
22
include requirements.txt
3-
include requirements-test.txt
3+
include requirements-test.txt
4+
include requirements-dev.txt
5+
include tox.ini

README.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ja: https://devdocs.line.me/ja/
1313
## Install
1414

1515
```
16-
$ pip install line_bot
16+
$ pip install line-bot-sdk
1717
```
1818

1919
## Synopsis
@@ -23,9 +23,14 @@ Usage is:
2323
```python
2424
from flask import Flask, request, abort
2525

26-
from line_bot import (
27-
LineBotApi, MessageEvent, TextMessage, TextSendMessage,
28-
WebhookParser, InvalidSignatureError
26+
from linebot import (
27+
LineBotApi, WebhookHandler
28+
)
29+
from linebot.exceptions import (
30+
InvalidSignatureError
31+
)
32+
from linebot.models import (
33+
MessageEvent, TextMessage, TextSendMessage,
2934
)
3035

3136
app = Flask(__name__)
@@ -70,7 +75,7 @@ def handle_message(event):
7075
Create a new LineBotApi instance.
7176

7277
```python
73-
line_bot_api = LineBotApi('YOUR_CHANNEL_ACCESS_TOKEN')
78+
line_bot_api = linebot.LineBotApi('YOUR_CHANNEL_ACCESS_TOKEN')
7479
```
7580

7681
You can override `timeout` value at each methods.
@@ -160,16 +165,16 @@ try:
160165
'to',
161166
TextSendMessage(text='Hello World!')
162167
)
163-
except LineBotApiError as e:
168+
except linebot.LineBotApiError as e:
164169
print(e.error.message)
165170
print(e.error.details)
166171
```
167172

168173
### Send message object
169174

170-
How to create Send message object
175+
https://devdocs.line.me/en/#send-message-object
171176

172-
(See also https://devdocs.line.me/en/#send-message-object)
177+
These following class in `linebot.models` package.
173178

174179
#### TextSendMessage
175180

@@ -360,7 +365,7 @@ carousel_template_message = TemplateSendMessage(
360365
#### \__init__(self, channel_secret)
361366

362367
```python
363-
parser = WebhookParser('YOUR_CHANNEL_SECRET')
368+
parser = linebot.WebhookParser('YOUR_CHANNEL_SECRET')
364369
```
365370

366371
#### parse(self, body, signature)
@@ -382,7 +387,7 @@ for event in events:
382387
#### \__init__(self, channel_secret)
383388

384389
```python
385-
handler = WebhookHandler('YOUR_CHANNEL_SECRET')
390+
handler = linebot.WebhookHandler('YOUR_CHANNEL_SECRET')
386391
```
387392

388393
#### handle(self, body, signature)
@@ -431,6 +436,8 @@ There is no handler for event, this default handler method is called.
431436

432437
https://devdocs.line.me/en/#webhooks
433438

439+
These following class in `linebot.models` package.
440+
434441
#### Event
435442

436443
* MessageEvent

examples/flask-echo/README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@ Sample echo-bot using [Flask](http://flask.pocoo.org/)
44

55
## Getting Start
66

7-
WebhookParser sample
8-
97
```
8+
$ export LINE_CHANNEL_SECRET=YOUR_LINE_CHANNEL_SECRET
9+
$ export LINE_CHANNEL_ACCESS_TOKEN=YOUR_LINE_CHANNEL_ACCESS_TOKEN
10+
1011
$ pip install -r requirements.txt
12+
```
13+
14+
Run WebhookParser sample
15+
16+
```
1117
$ python app.py
1218
```
1319

14-
WebhookHandler sample
20+
Run WebhookHandler sample
1521

1622
```
17-
$ pip install -r requirements.txt
1823
$ python app_with_handler.py
1924
```

examples/flask-echo/app.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
14
import os
5+
import sys
26
from argparse import ArgumentParser
37

48
from flask import Flask, request, abort
59

6-
from line_bot import (
10+
from linebot import (
711
LineBotApi, WebhookParser
812
)
9-
from line_bot.exceptions import (
13+
from linebot.exceptions import (
1014
InvalidSignatureError
1115
)
12-
from line_bot.models import (
16+
from linebot.models import (
1317
MessageEvent, TextMessage, TextSendMessage,
1418
)
1519

1620
app = Flask(__name__)
1721

1822
# get channel_secret and channel_access_token from your environment variable
1923
channel_secret = os.getenv('LINE_CHANNEL_SECRET', None)
20-
if channel_secret is None:
21-
print('Specify LINE_CHANNEL_SECRET as env.')
2224
channel_access_token = os.getenv('LINE_CHANNEL_ACCESS_TOKEN', None)
25+
if channel_secret is None:
26+
print('Specify LINE_CHANNEL_SECRET as environment variable.')
27+
sys.exit(1)
2328
if channel_access_token is None:
24-
print('Specify LINE_CHANNEL_ACCESS_TOKEN as env.')
29+
print('Specify LINE_CHANNEL_ACCESS_TOKEN as environment variable.')
30+
sys.exit(1)
2531

2632
line_bot_api = LineBotApi(channel_access_token)
2733
parser = WebhookParser(channel_secret)

examples/flask-echo/app_with_handler.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
import os
2+
import sys
23
from argparse import ArgumentParser
34

45
from flask import Flask, request, abort
56

6-
from line_bot import (
7+
from linebot import (
78
LineBotApi, WebhookHandler
89
)
9-
from line_bot.exceptions import (
10+
from linebot.exceptions import (
1011
InvalidSignatureError
1112
)
12-
from line_bot.models import (
13+
from linebot.models import (
1314
MessageEvent, TextMessage, TextSendMessage,
1415
)
1516

1617
app = Flask(__name__)
1718

1819
# get channel_secret and channel_access_token from your environment variable
1920
channel_secret = os.getenv('LINE_CHANNEL_SECRET', None)
20-
if channel_secret is None:
21-
print('Specify LINE_CHANNEL_SECRET as env.')
2221
channel_access_token = os.getenv('LINE_CHANNEL_ACCESS_TOKEN', None)
22+
if channel_secret is None:
23+
print('Specify LINE_CHANNEL_SECRET as environment variable.')
24+
sys.exit(1)
2325
if channel_access_token is None:
24-
print('Specify LINE_CHANNEL_ACCESS_TOKEN as env.')
26+
print('Specify LINE_CHANNEL_ACCESS_TOKEN as environment variable.')
27+
sys.exit(1)
2528

2629
line_bot_api = LineBotApi(channel_access_token)
2730
handler = WebhookHandler(channel_secret)

examples/flask-echo/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
line_bot
1+
line-bot-sdk
22
flask

examples/flask-kitchensink/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ Sample bot using [Flask](http://flask.pocoo.org/)
55
## Getting Start
66

77
```
8+
$ export LINE_CHANNEL_SECRET=YOUR_LINE_CHANNEL_SECRET
9+
$ export LINE_CHANNEL_ACCESS_TOKEN=YOUR_LINE_CHANNEL_ACCESS_TOKEN
10+
811
$ pip install -r requirements.txt
12+
913
$ python app.py
1014
```

examples/flask-kitchensink/app.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33

44
import errno
55
import os
6+
import sys
67
from argparse import ArgumentParser
78

89
from flask import Flask, request, abort
910

10-
from line_bot import (
11+
from linebot import (
1112
LineBotApi, WebhookHandler
1213
)
13-
from line_bot.exceptions import (
14+
from linebot.exceptions import (
1415
InvalidSignatureError
1516
)
16-
from line_bot.models import (
17+
from linebot.models import (
1718
MessageEvent, TextMessage, TextSendMessage,
1819
SourceUser, SourceGroup, SourceRoom,
1920
TemplateSendMessage, ConfirmTemplate, MessageTemplateAction,
@@ -28,11 +29,13 @@
2829

2930
# get channel_secret and channel_access_token from your environment variable
3031
channel_secret = os.getenv('LINE_CHANNEL_SECRET', None)
31-
if channel_secret is None:
32-
print('Specify LINE_CHANNEL_SECRET as env.')
3332
channel_access_token = os.getenv('LINE_CHANNEL_ACCESS_TOKEN', None)
33+
if channel_secret is None:
34+
print('Specify LINE_CHANNEL_SECRET as environment variable.')
35+
sys.exit(1)
3436
if channel_access_token is None:
35-
print('Specify LINE_CHANNEL_ACCESS_TOKEN as env.')
37+
print('Specify LINE_CHANNEL_ACCESS_TOKEN as environment variable.')
38+
sys.exit(1)
3639

3740
line_bot_api = LineBotApi(channel_access_token)
3841
handler = WebhookHandler(channel_secret)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
line_bot
1+
line-bot-sdk
22
flask

examples/simple-server-echo/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ Sample echo-bot using [wsgiref.simple_server](https://docs.python.org/3/library/
55
## Getting Start
66

77
```
8+
$ export LINE_CHANNEL_SECRET=YOUR_LINE_CHANNEL_SECRET
9+
$ export LINE_CHANNEL_ACCESS_TOKEN=YOUR_LINE_CHANNEL_ACCESS_TOKEN
10+
811
$ pip install -r requirements.txt
12+
913
$ python app.py
1014
```
1115

0 commit comments

Comments
 (0)