interact with product apis

class FunctionNames[source]

FunctionNames(branchName:str='dev-manual')

determine function and resources name based on branchName

class Line[source]

Line(accessKey:str='')

the main class for interacting with product endpoint
user/pw are optional

class LineLambda[source]

LineLambda(user=None, pw=None, region='ap-southeast-1')

Testing

generate dummy data for testing

Create main class object

line = Line(accessKey = accessKey)

sendMessage

%%time
result = line.send(roomId = sampleInput['roomId'], message= sampleInput['message'])
print(result)
---------------------------------------------------------------------------
LineBotApiError                           Traceback (most recent call last)
<timed exec> in <module>

<ipython-input-14-655cd6ee6e8c> in send(self, message, roomId)
     11 
     12   def send(self, message:str = '', roomId:str=''):
---> 13     self.line_bot_api.push_message(roomId, TextSendMessage(text = message))
     14     return True
     15 

~/anaconda3/envs/python38/lib/python3.8/site-packages/linebot/api.py in push_message(self, to, messages, retry_key, notification_disabled, timeout)
    145         }
    146 
--> 147         self._post(
    148             '/v2/bot/message/push', data=json.dumps(data), timeout=timeout
    149         )

~/anaconda3/envs/python38/lib/python3.8/site-packages/linebot/api.py in _post(self, path, endpoint, data, headers, timeout)
   1151         )
   1152 
-> 1153         self.__check_error(response)
   1154         return response
   1155 

~/anaconda3/envs/python38/lib/python3.8/site-packages/linebot/api.py in __check_error(response)
   1173             pass
   1174         else:
-> 1175             raise LineBotApiError(
   1176                 status_code=response.status_code,
   1177                 headers=dict(response.headers.items()),

LineBotApiError: LineBotApiError: status_code=429, request_id=f8dbe399-7e08-4b34-88f1-9389e32685da, error_response={"details": [], "message": "You have reached your monthly limit."}, headers={'Server': 'openresty', 'Content-Type': 'application/json', 'x-line-request-id': 'f8dbe399-7e08-4b34-88f1-9389e32685da', 'x-content-type-options': 'nosniff', 'x-xss-protection': '1; mode=block', 'x-frame-options': 'DENY', 'Content-Length': '50', 'Expires': 'Mon, 19 Oct 2020 05:03:02 GMT', 'Cache-Control': 'max-age=0, no-cache, no-store', 'Pragma': 'no-cache', 'Date': 'Mon, 19 Oct 2020 05:03:02 GMT', 'Connection': 'close'}

SendNotify

%%time
result = line.sendNotify(message = 'nothing', token = 'ECycqerh1xQKGlXAb2qifyz39A0GW8LHyX1hBBFSQGl')
result.text
CPU times: user 13.3 ms, sys: 64 µs, total: 13.4 ms
Wall time: 311 ms
'{"status":200,"message":"ok"}'

Lambda

%%time
result = Line.lambdaSend(sampleInput, '')

Call function using deployed Lambda function

%%time
lineLambda = LineLambda(USER, PW)
lineLambda.send(message='hello', roomId = sampleInput['roomId'])
CPU times: user 12.8 ms, sys: 3.65 ms, total: 16.4 ms
Wall time: 39.2 ms
True
%%time
result = LineLambda().notify(message = 'nothing', token = 'ECycqerh1xQKGlXAb2qifyz39A0GW8LHyX1hBBFSQGl')
CPU times: user 16.1 ms, sys: 0 ns, total: 16.1 ms
Wall time: 48.4 ms