-
Notifications
You must be signed in to change notification settings - Fork 0
Documentation
class linelib.Client(
self,
channel_secret: str,
channel_access_token: str,
*args, **options: Any
)
Represents a LINE Official Account (Client).
parameter | type | default | description |
---|---|---|---|
channel_secret | str |
required | Channel secret. |
channel_access_token | str |
required | Channel access token. |
*args, **options | Any |
() , {}
|
No usage provided. |
import logging
from linelib import Client
client = Client('channel secret', 'channel access token')
-
CS :
str
- Channel secret. -
CAT :
str
- Channel access token. -
app :
Flask
- (Running) Flask application. Note that it has been usedCORS(app)
-
headers :
dict
- Headers for requests. -
loop :
Loop
- Asyncio event loop. -
_EVENTS* :
dict
- Saved event handlers. -
_VALID_EVENTS* :
list
- Current valid events.
*
- These attributes should not be overwritten or deleted by the user.
def createEvents(
self,
name: str,
obj: type
) -> None
Save the provided content to Client._EVENTS
.
parameter | type | default | description |
---|---|---|---|
name | str |
required | Event name. |
obj | type |
required | An event object. |
from linelib import Client
client = Client(...)
class ControlledEventObject:
def __init__(self, json: dict):
self.type = json['type'] # event type, REQUIRED
self.options = json['options'] # additional options, REQUIRED
async def emit(self, ctx):
await ctx.reply('Hello, World!')
obj = ControlledEventObject({
'type': 'text', # text message event
'options': () # Empty
})
client.createEvents('text', obj) # registers the event handler
def emitEvents(
self,
name: str,
*args: Any,
**kwargs: Any
) -> None
Runs the events inside Client._EVENTS
.
parameter | type | default | description |
---|---|---|---|
name | str |
required | The event name. |
*args, **kwargs | Any |
() , {}
|
Any arguments to add for the event handlers. |
from linelib import Client
client = Client(...)
@client.event('ready')
async def execute_me():
print("I just got executed!")
client.emitEvents('ready') # no arguments required
@Client.event(
self,
listener: str,
*options
) -> EventObject
Registers an event handler. See Client._VALID_EVENTS
to see a list of valid events.
Decorator Parameters
parameter | type | default | description |
---|---|---|---|
listener | Union[str, Callable] |
FUNCTION_NAME_OR_LISTENER |
Listener name or leave blank. |
FUNCTION_NAME_OR_LISTENER
- You can pass in a valid function (Client._VALID_EVENTS
), or you can leave this blank and let linelib detect your function name. (Prefix:on_
+ Event name)
Handler Parameters
Handlers must be async (coroutine) functions.
parameter | type | description |
---|---|---|
ctx? None? |
Depends |
The specification depends on the event type. |
Depends: ctx? None?
event name | argument(s) | type | description |
---|---|---|---|
ready |
❌ | ❌ | No arguments should be passed. |
text |
ctx | TextMessageEvent |
The text message context. |
postback |
ctx | PostbackEvent |
The postback context. |
from linelib import Client
client = Client(...)
# method 1
@client.event('ready')
async def ready(): # any name you want
print("WOW!")
# method 2
@client.event()
async def on_ready(): # on_{EVENT_NAME}
print("Wow, again -- wow!!")
client.run(...)
@modifiable(req=dict)
def request_then(self, req: dict) -> Any
This function is overwritable (modifiable). This will be executed once LINELIB receives the webhook event from LINE.
@modifiable(ctx=type)
def payload_then(self, ctx) -> Any
This function is overwritable (modifiable). This will be executed once Linelib has got the context.
Note:
ready
event is NOT included!
def Client.run(
self,
*args,
**options: Any
)
Runs the LINE bot.
parameter | type | default | description |
---|---|---|---|
*args | Any |
() |
Meaningless. This does not do anything here. |
**options | Any |
{} |
Configure run options. See Client Options → |
option | type | description | example |
---|---|---|---|
log_level | level |
Sets the logger level of Flask. | log_level=logging.ERROR |
show_logs | bool |
Show linelib logs? | show_logs=False |
* | Any |
Unnamed for linelib, only for app.run options. |
threaded=True |
from linelib import Client
client = Client(...)
client.run(log_level=logging.ERROR, show_logs=False, threaded=True)
Thanks for taking your time to read my awful documentation and guides.
Note that if you're interested, please also check out the Official LINE Documentation!
Hello! I am a cute sidebar that makes you to read this whole text with no doubt.
I was born in 1969 and collaborated with Gustavo Fring for my entire life, and my motto is: "Life is a career."
Actually, I have a more important announcement to make besides my profile.
My name is Sustavo Fring, but you can call me Sus.
I am the secondary owner of Los Pollos Hermanos that almost nobody knows.
Gustavo and I created an empire.
I AM THE DANGER.
My name is Walter Hartwell White. I live at-