예제 #1
0
 def setUp(self):
     self.tested = Client(
         client_id='QxUxF..........i51eITH',
         client_secret='fmtJS3GOVTPn4....................bFcIvJf1jo',
         redirect_uri='http://localhost:5000/notify')
     self.token = '123456789abcdefghidhFeXkIQVjmuI6Oz123456789'
     self.bot_origin = "https://notify-bot.line.me"
     self.api_origin = "https://notify-api.line.me"
    def post(self):
        payload = request.get_json()
        client = Client(client_id=payload['client_id'],
                        SECRET=payload['client_secret'],
                        redirect_uri=payload['redirect_uri'])

        token = client.get_access_token(code=payload.get('code'))
        return {'token': token}
 def post(self):
     payload = request.get_json()
     client = Client(client_id=payload['clientId'],
                     redirect_uri=payload['redirectUri'])
     state = uuid.uuid4()
     if payload.get('state'):
         state = payload.get('state')
     link = client.get_auth_link(state=state)
     return {'link': link}
def sticker_text(event):
    if ('brown' in event.message.keywords or 'edward' in event.message.keywords) \
            and os.getenv('LOTIFY_SWITCH') == 'ON':

        user = line_bot_api.get_profile(user_id=event.source.user_id)
        lotify = Client()
        lotify.send_message(
            access_token=os.getenv('LOTIFY_TOKEN'),
            message=f'🎉 {user.display_name} 🏃‍♂️ {user.picture_url}')
        sticker = StickerSendMessage(package_id='6136', sticker_id='10551379')
    else:
        sticker = StickerSendMessage(package_id='8525', sticker_id='16581310')
    line_bot_api.reply_message(event.reply_token, sticker)
예제 #5
0
def send_message(message, access_token, image_url, image_file):
    client = Client()
    if image_url is not None:
        client.send_message_with_image_url(access_token, message, image_url,
                                           image_url)
    elif image_file is not None:
        client.send_message_with_image_file(access_token, message,
                                            open(image_file, 'rb'))
    else:
        client.send_message(access_token, message)
    click.echo("Send notification success.")
예제 #6
0
def send_message(message, access_token, image_url, image_file):
    client = Client()
    if image_url != "":
        client.send_message_with_image_url(access_token, message, image_url,
                                           image_url)
    elif image_file != "":
        client.send_message_with_image_file(access_token, message,
                                            open(image_file, 'rb'))
    else:
        client.send_message(access_token, message)
    click.echo("send successfully")
예제 #7
0
import argparse

from lotify.client import Client

if __name__ == '__main__':
    lotify = Client()
    parser = argparse.ArgumentParser()
    parser.add_argument("--token",
                        required=True,
                        help="LINE Notify access_token")
    parser.add_argument("--message", required=True, help="LINE Notify message")
    parser.add_argument("--image-url", help="Image url")
    parser.add_argument("--image-file", help="Image file")
    parser.add_argument("--sticker-id", help="LINE sticker id")
    parser.add_argument("--package-id", help="LINE package id")
    args = parser.parse_args()
    if args.image_url:
        lotify.send_message_with_image_url(message=args.message,
                                           access_token=args.token,
                                           image_fullsize=args.image_url,
                                           image_thumbnail=args.image_url)
    elif args.sticker_id and args.package_id:
        lotify.send_message_with_sticker(message=args.message,
                                         access_token=args.token,
                                         sticker_id=args.sticker_id,
                                         sticker_package_id=args.package_id)
    elif args.image_file:
        lotify.send_message_with_image_file(message=args.message,
                                            access_token=args.token,
                                            file=open(args.image_file,
                                                      'rb').read())
예제 #8
0
from model.request_model import ImageUrlRequestBody, StickerRequestBody, TextRequestBody
from model.response_model import NotifyResponse

CLIENT_ID = os.getenv('LINE_NOTIFY_CLIENT_ID')
SECRET = os.getenv('LINE_NOTIFY_CLIENT_SECRET')
URI = os.getenv('LINE_NOTIFY_REDIRECT_URI')

"""
If your keys are 

LINE_NOTIFY_CLIENT_ID, LINE_NOTIFY_CLIENT_SECRET, LINE_NOTIFY_REDIRECT_URI

you can drop them in Client() cause they are default environment name.
"""
lotify = Client(client_id=CLIENT_ID, client_secret=SECRET, redirect_uri=URI)


class TextController(Resource):
    @swagger.doc({
        'tags': ['Text'],
        'description': 'Send LINE Noitfy text message',
        'operationId': 'sendText',
        'parameters': [{
            'name': 'body',
            'description': 'Send LINE Noitfy text message',
            'in': 'body',
            'schema': TextRequestBody,
            'required': True
        }],
        'responses': {
예제 #9
0
class TestClient(unittest.TestCase):
    def setUp(self):
        self.tested = Client(
            client_id='QxUxF..........i51eITH',
            client_secret='fmtJS3GOVTPn4....................bFcIvJf1jo',
            redirect_uri='http://localhost:5000/notify')
        self.token = '123456789abcdefghidhFeXkIQVjmuI6Oz123456789'
        self.bot_origin = "https://notify-bot.line.me"
        self.api_origin = "https://notify-api.line.me"

    def test_get_auth_link(self):
        result = self.tested.get_auth_link('foo')
        expected_query_string = {
            'scope': 'notify',
            'response_type': 'code',
            'client_id': 'QxUxF..........i51eITH',
            'redirect_uri': 'http://localhost:5000/notify',
            'state': 'foo'
        }
        self.assertEqual(
            result, '{url}/oauth/authorize?{query_string}'.format(
                url=self.bot_origin,
                query_string=urlencode(expected_query_string)))

    @responses.activate
    def test_get_access_token(self):
        responses.add(responses.POST,
                      '{url}/oauth/token'.format(url=self.bot_origin),
                      json={'access_token': self.token},
                      status=200)

        result = self.tested.get_access_token('foo')
        request = responses.calls[0]
        response = json.loads(request.response.content.decode())
        self.assertEqual('POST', request.request.method)
        self.assertEqual(self.token, response.get('access_token'))
        self.assertEqual(result, response.get('access_token'))

    @responses.activate
    def test_status(self):
        expect_response = {
            'status': 200,
            'message': 'ok',
            'targetType': 'USER',
            'target': 'NiJia Lin'
        }
        responses.add(responses.GET,
                      '{url}/api/status'.format(url=self.api_origin),
                      json=expect_response,
                      status=200)

        result = self.tested.status(self.token)
        request = responses.calls[0]
        response = json.loads(request.response.content.decode())
        self.assertEqual('GET', request.request.method)
        self.assertEqual(200, response.get('status'))
        self.assertEqual(result, expect_response)

    @responses.activate
    def test_send_message(self):
        expect_response = {'status': 200, 'message': 'ok'}
        responses.add(responses.POST,
                      '{url}/api/notify'.format(url=self.api_origin),
                      json=expect_response,
                      status=200)

        result = self.tested.send_message(self.token,
                                          message='This is notify message')
        request = responses.calls[0]
        response = json.loads(request.response.content.decode())
        self.assertEqual('POST', request.request.method)
        self.assertEqual(200, response.get('status'))
        self.assertEqual(result, expect_response)

    @responses.activate
    def test_send_message_with_sticker(self):
        expect_response = {'status': 200, 'message': 'ok'}
        responses.add(responses.POST,
                      '{url}/api/notify'.format(url=self.api_origin),
                      json=expect_response,
                      status=200)

        result = self.tested.send_message_with_sticker(
            self.token,
            message='This is notify message',
            sticker_package_id=1,
            sticker_id=1)

        request = responses.calls[0]
        response = json.loads(request.response.content.decode())
        self.assertEqual('POST', request.request.method)
        self.assertEqual(200, response.get('status'))
        self.assertEqual(result, expect_response)

    @responses.activate
    def test_send_message_with_image_url(self):
        expect_response = {'status': 200, 'message': 'ok'}
        responses.add(responses.POST,
                      '{url}/api/notify'.format(url=self.api_origin),
                      json=expect_response,
                      status=200)

        result = self.tested.send_message_with_image_url(
            self.token,
            message='This is notify message',
            image_thumbnail='https://image.com/abc.png',
            image_fullsize='https://image.com/abc.png')

        request = responses.calls[0]
        response = json.loads(request.response.content.decode())
        self.assertEqual('POST', request.request.method)
        self.assertEqual(200, response.get('status'))
        self.assertEqual(result, expect_response)

    @responses.activate
    def test_send_message_with_image_file(self):
        expect_response = {'status': 200, 'message': 'ok'}
        responses.add(responses.POST,
                      '{url}/api/notify'.format(url=self.api_origin),
                      json=expect_response,
                      status=200)
        result = self.tested.send_message_with_image_file(
            self.token,
            message='This is notify message',
            file='This is file object')

        request = responses.calls[0]
        response = json.loads(request.response.content.decode())
        self.assertEqual('POST', request.request.method)
        self.assertEqual(200, response.get('status'))
        self.assertEqual(result, expect_response)

    @responses.activate
    def test_revoke(self):
        expect_response = {'status': 200, 'message': 'ok'}
        responses.add(responses.POST,
                      '{url}/api/revoke'.format(url=self.api_origin),
                      json=expect_response,
                      status=200)

        result = self.tested.revoke('access_token')
        request = responses.calls[0]
        response = json.loads(request.response.content.decode())
        self.assertEqual('POST', request.request.method)
        self.assertEqual(200, response.get('status'))
        self.assertEqual(result, expect_response)
예제 #10
0
파일: d2l.py 프로젝트: MirrorShih/kiwawa
import discord
from discord.ext import commands

from lotify.client import Client

import os
import json

bot = commands.Bot(command_prefix='>')
discordbot_token = os.environ['DISCORDBOT_TOKEN']
lotify_token = os.environ['LOTIFY_TOKEN']
discord_webhook_id = int(os.environ['DISCORD_WEBHOOK'].split('/')[-2])
message_channel_id = os.environ.get('MESSAGE_CHANNEL_ID', None)
lotify = Client()


@bot.command()
async def ping(ctx):
    lotify.send_message(
        access_token=lotify_token,
        message='pong'
    )
    await ctx.send('pong')


@bot.listen()
async def on_message(message):
    if message.webhook_id == discord_webhook_id: return
    if message_channel_id is not None and (message.channel.id != int(message_channel_id)): return
    lotify_message = "<" + message.author.display_name + ">:\n"
    lotify_message += message.content
            password=PASSWORD,
            host=HOST,
            port=PORT
        )
        self.conns.append(conn)

        return conn

    def __exit__(self, type, value, traceback):
        for conn in self.conns:
            conn.close()

        self.conns.clear()


lotify = Client()
print("Connecting...")
print("Cursor start...")
with Database() as db, db.connect() as conn, conn.cursor(
        cursor_factory=psycopg2.extras.RealDictCursor) as cur:
    cur.execute(f'''
        SELECT "user".notify_token, user_site.* from "user" LEFT JOIN user_site ON "user".line_id = user_site.line_id
    ''')
    users = cur.fetchall()
    cur.execute(f'''
        SELECT  us.line_id, taiwan.* from user_site as us LEFT JOIN taiwan ON us.site_name = taiwan.site_name
    ''')
    sites = cur.fetchall()
    print("Fetch data success!")
print('Close connection')
messages = ''
예제 #12
0
import os

from lotify.client import Client

if __name__ == '__main__':
    lotify = Client()
    message = os.getenv("INPUT_MESSAGE")
    token = os.getenv("INPUT_TOKEN")
    image = os.getenv('INPUT_IMAGE_URL')
    sticker = os.getenv('INPUT_STICKER_ID')
    package = os.getenv('INPUT_PACKAGE_ID')
    if image:
        lotify.send_message_with_image_url(message=message,
                                           access_token=token,
                                           image_fullsize=image,
                                           image_thumbnail=image)
    elif sticker and package:
        lotify.send_message_with_sticker(message=message,
                                         access_token=token,
                                         sticker_id=sticker,
                                         sticker_package_id=package)
    else:
        lotify.send_message(message=message, access_token=token)
    print('end')