Code Monkey home page Code Monkey logo

python-wechaty-puppet-service's Introduction

wechaty-puppet-service Python 3.7 PyPI GitHub Actions

Powered by Wechaty

Service

PyPI Version PyPI - Downloads

Python Service Puppet for Wechaty

Features

  1. Consume Wechaty Puppet Service

Usage

import asyncio
from wechaty import Wechaty
from wechaty_puppet_service import PuppetService

bot = Wechaty(PuppetService("your-token-here"))
bot.on('message', lambda x: print(x))

asyncio.run(bot.start())

Environment Variables

1 WECHATY_PUPPET_SERVICE_TOKEN

The token set to this environment variable will become the default value of puppetOptions.token

WECHATY_PUPPET_SERVICE_TOKEN=secret python bot.py

or you can use TOKEN or token environment variable alias name to set token, for example:

TOKEN=secret python bot.py
# or
token=secret python bot.py

History

master

v0.7 (Mar, 2021)

Rename from wechaty-puppet-hostie -> wechaty-puppet-service

v0.0.1 (Mar 10, 2020)

  1. Init Python version
  2. Published to PyPI

Authors

Copyright & License

  • Code & Docs © 2020-now Huan LI <[email protected]>
  • Code released under the Apache-2.0 License
  • Docs released under Creative Commons

python-wechaty-puppet-service's People

Contributors

aiamber avatar fish-ball avatar huan avatar huangaszaq avatar lyleshaw avatar univerone avatar why2lyj avatar wj-mcat avatar yangruihan avatar yangte1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

python-wechaty-puppet-service's Issues

api error that occur during testing

  • data = await puppet.contact_alias(id='token', alias='mylove')
grpclib.exceptions.GRPCError: (<Status.INTERNAL: 13>, 'CacheManager getContact() has no cache.', None)
  • data = await puppet.contact_self_q_r_code()
grpclib.exceptions.GRPCError: (<Status.INTERNAL: 13>, 'Wechaty Puppet Unsupported API Error. Learn More At https://github.com/wechaty/wechaty-puppet/wiki/Compatibility', None)
  • room_qrcode = await puppet.room_q_r_code(id='room-id')
grpclib.exceptions.GRPCError: (<Status.INTERNAL: 13>, 'Wechaty Puppet Unsupported API Error. Learn More At https://github.com/wechaty/wechaty-puppet/wiki/Compatibility', None)
  • data = await puppet.contact_self_name(name='秋天')
grpclib.exceptions.GRPCError: (<Status.INTERNAL: 13>, 'Wechaty Puppet Unsupported API Error. Learn More At https://github.com/wechaty/wechaty-puppet/wiki/Compatibility', None)
  • data = await puppet.contact_self_signature()
grpclib.exceptions.GRPCError: (<Status.INTERNAL: 13>, 'Wechaty Puppet Unsupported API Error. Learn More At https://github.com/wechaty/wechaty-puppet/wiki/Compatibility', None)

failed send FileBox with stream Type

stream 模式的 FileBox 无法发送

@dataclass
class FileBoxOptionsStream(FileBoxOptionsBase):
    """
    stream file-box options
    """
    # TODO -> recheck the stream data type
    stream: bytes = b''
    type: FileBoxType = FileBoxType.Stream

而对应的

class FileBoxEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, bytes):
            return str(obj, encoding='utf-8')

        return json.JSONEncoder.default(self, obj)

因为 stream 是二进制的,且不是 utf8 格式,所以这里转换会失败

ERROR:root:'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte

所以我觉得 FileBoxEncoder 可以再改改。

我可以来提供 PR

get into trouble with contact_avatar grpc method

When we call method from chatie-grpc:

response = await self.puppet_stub.contact_avatar(id=contact_id)

we will receive error :

2020-06-23 19:51:17,895 - Wechaty - ERROR - internal error <(<Status.INTERNAL: 13>, 'FileBox.toJSON() can only work on limited FileBoxType(s). See: <https://github.com/huan/file-box/issues/25>', None)>
ERROR:Wechaty:internal error <(<Status.INTERNAL: 13>, 'FileBox.toJSON() can only work on limited FileBoxType(s). See: <https://github.com/huan/file-box/issues/25>', None)>

It seems that this error is from hostie-server. @huan

some puppet-hostie function has not been implemented

  1. Please run the following command and check whether the problem has been fixed:
pip uninstall -r requirements.txt
pip install -r requirements.txt
python your-bot.py
  1. there are some puppet-hostie functions which have not been implemented.
  • room_validate
  • room_payload_dirty
  • room_member_payload_dirty
  1. there are some puppet-hostie functions which is not correct.
  • message_file
  • init_puppet

which should be with start function not in __init__ function . this is mentioned by Huan a few months ago.

  • room_search

hostie stucked when connected to Wechaty Gateway Server with Padlocal token

Just switched to padlocal token.

Started my endpoint (gateway server). Got logs:

10:40:01 VERB Wechaty initPuppetEventBridge() puppet.on(error) (listenerCount:0) registering...
10:40:01 VERB Wechaty initPuppetEventBridge() puppet.on(heartbeat) (listenerCount:0) registering...
10:40:01 VERB Wechaty initPuppetEventBridge() puppet.on(ready) (listenerCount:0) registering...
10:40:01 VERB Wechaty initPuppetEventBridge() puppet.on(reset) (listenerCount:0) registering...
10:40:01 VERB Wechaty wechatifyUserModules(Puppet#0(mytokenxx123766x))
10:40:01 VERB StateSwitch on(pending) <- (false)
10:40:01 INFO
============================================================
Welcome to Wechaty PadLocal puppet!

   - wechaty-puppet-padlocal version: 0.2.3
   - padlocal-ts-client version: 0.2.3
  ============================================================

10:40:01 VERB Wechaty on(heartbeat, listener) registering... listenerCount: 1
10:40:01 VERB StateSwitch on(true) <- (pending)
10:40:01 VERB IoClient startHostie()
10:40:01 VERB PuppetServer constructor({endpoint: "0.0.0.0:9001", puppet: "Puppet#0(mytokenxxxxxx)", token: "mytokenxxxxxx"})
10:40:01 VERB PuppetServer start()
10:40:01 VERB EventStreamManager constructor(Puppet#0(mytokenxxxxxx))
10:40:01 VERB StateSwitch on(true) <- (pending)
10:40:01 VERB [PuppetPadlocal] start login with type: QrLogin
10:40:02 VERB [PuppetPadlocal] scan event, status: Waiting, with qrcode: http://weixin.qq.com/x/AbXxxxxxOXGBn
10:40:02 INFO IoClient [2] http://weixin.qq.com/x/AbXxxxxOXGBn
Online QR Code Image: https://wechaty.js.org/qrcode/http%3A%2F%2Fweixin.qq.com%2Fx%xxxxwXrlv-1OXGBn

On the python side, everything looks fine. But no QR code popped up. The hostile exit after stucking for a while.

I got logs:

2021-01-07 02:40:45,412 - Wechaty - INFO - init_puppet_event_bridge() <<wechaty_puppet_hostie.puppet.HostiePuppet object at 0x11f5e7b80>>
2021-01-07 02:40:45,412 - Wechaty - INFO - initPuppetEventBridge() puppet.on(dong) (listenerCount:1) registering...
2021-01-07 02:40:45,412 - Wechaty - INFO - initPuppetEventBridge() puppet.on(error) (listenerCount:1) registering...
2021-01-07 02:40:45,412 - Wechaty - INFO - initPuppetEventBridge() puppet.on(heart-beat) (listenerCount:1) registering...
2021-01-07 02:40:45,412 - Wechaty - INFO - initPuppetEventBridge() puppet.on(ready) (listenerCount:1) registering...
2021-01-07 02:40:45,412 - Wechaty - INFO - receive event <%s>
2021-01-07 02:40:45,412 - Wechaty - INFO - initPuppetEventBridge() puppet.on(reset) (listenerCount:0) registering...
2021-01-07 02:40:45,412 - Wechaty - INFO - initPuppetEventBridge() puppet.on(friendship) (listenerCount:1) registering...
2021-01-07 02:40:45,412 - Wechaty - INFO - initPuppetEventBridge() puppet.on(login) (listenerCount:1) registering...
2021-01-07 02:40:45,413 - Wechaty - INFO - initPuppetEventBridge() puppet.on(logout) (listenerCount:1) registering...
2021-01-07 02:40:45,413 - Wechaty - INFO - initPuppetEventBridge() puppet.on(message) (listenerCount:1) registering...
2021-01-07 02:40:45,413 - Wechaty - INFO - initPuppetEventBridge() puppet.on(room-invite) (listenerCount:1) registering...
2021-01-07 02:40:45,413 - Wechaty - INFO - initPuppetEventBridge() puppet.on(room-join) (listenerCount:1) registering...
2021-01-07 02:40:45,413 - Wechaty - INFO - initPuppetEventBridge() puppet.on(room-leave) (listenerCount:1) registering...
2021-01-07 02:40:45,413 - Wechaty - INFO - initPuppetEventBridge() puppet.on(room-topic) (listenerCount:1) registering...
2021-01-07 02:40:45,413 - Wechaty - INFO - initPuppetEventBridge() puppet.on(scan) (listenerCount:1) registering...
2021-01-07 02:40:45,413 - Wechaty - INFO - starting puppet ...
2021-01-07 02:40:45,413 - HostiePuppet - INFO - init puppet
2021-01-07 02:40:45,414 - HostiePuppet - INFO - starting the puppet ... <<<<< stucked here.
2021-01-07 02:43:16,481 - Wechaty - ERROR - The network is not good, the bot will try to restart after 60 seconds.
2021-01-07 02:44:16,486 - Wechaty - INFO - restarting the bot ...
2021-01-07 02:44:16,486 - Wechaty - INFO - wechaty is stoping ...
2021-01-07 02:44:16,486 - Wechaty - INFO - stopping - stop puppet
2021-01-07 02:44:16,486 - HostiePuppet - INFO - stop()

pre-commit tool required.

As used in python-wechaty repo, pre-commit can keep every commit tested and bump a new version to track our changes. So, this tool is essential for python-wechaty.

Using ping will cause to raise an exception, but message missing

Hi, wechaty is awesome! Thanks for everything.

I got Wechaty - ERROR - The network is not good, the bot will try to restart after 60 seconds., when I start my custom boy with config WECHATY_PUPPET_SERVICE_ENDPOINT=127.0.0.1:xxxx.

I found this code cause it:

if ping(self.options.end_point) is False:
raise WechatyPuppetConfigurationError(
f"can't not ping endpoint: {self.options.end_point}"
)

ping('127.0.0.1') will raise an exception "permission denied", but exception message missing, It's not friendly.

ping3 pointer that should run as root.

An internal error from function to_file_box()

function to_file_box() internal error

  • wechaty puppet version: wechaty docker 0.65
  • wechaty version: python wechaty 0.8.24
  • token: padlocal token

Description

Sometimes internal error will occur when saving image from receiver or talker, and then download file failed. Please take a look, thanks.

Reproduce your problem

SUPPORTED_MESSAGE_FILE_TYPES: List[MessageType] = [
    MessageType.MESSAGE_TYPE_ATTACHMENT,
    MessageType.MESSAGE_TYPE_IMAGE,
    MessageType.MESSAGE_TYPE_EMOTICON,
    MessageType.MESSAGE_TYPE_VIDEO,
    MessageType.MESSAGE_TYPE_AUDIO
]

async def on_message(self, msg: Message):
    if msg.type() in SUPPORTED_MESSAGE_FILE_TYPES:
        file_box = await msg.to_file_box()
        if file_box is not None:
            await file_box.to_file(file_box.name)

Error log

2021-08-28 20:15:36,517 - Wechaty - ERROR - internal error <(<Status.UNKNOWN: 2>, '[tid:1aff233b] [11014ms] download file failed:{"host":{"host":"180.111.198.203","port":80},"payload":"qwAAA4xOIFuIHZ0AAAAAAAAAAAAAAAADcwAAAAN2ZXIAAAABMQAAAAl3ZWl4aW5udW0AAAAKMjYzNTk1ODM2MwAAAANzZXEAAAABNgAAAA1jbGllbnR2ZXJzaW9uAAAACTQwMjY1NDc1NAAAAAxjbGllbnRvc3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=","unpackaeskey":"3Pa/o8iamL8Gdoq3=="}, received null response', None)>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.