关闭

itchat微信自动回复消息

标签: 微信api
2536人阅读 评论(0) 收藏 举报
分类:

使用之前需要准备的工作:安装itchat API
easy_install itchat

#coding=utf8
import itchat,time
from itchat.content import *

'''
##自动回复的功能
@itchat.msg_register(itchat.content.TEXT)
def text_reply(msg):
    return msg['Text']
'''
@itchat.msg_register([TEXT,MAP,CARD,NOTE,SHARING])
def text_reply(msg):
    itchat.send('%s: %s'%(msg['Type'],msg['Text']),msg['FromUserName'])

@itchat.msg_register([PICTURE,RECORDING,ATTACHMENT,VIDEO])
def download_files(msg):
    msg['Text'](msg['FileName'])
    return '@%s@%s'%({'Picture':'img','Video':'vid'}.get(msg['Type'],'fil'),msg['FileName'])

@itchat.msg_register(FRIENDS)
def add_friend(msg):
    itchat.add_friend(**msg['Text'])# 该操作将自动将好友的消息录入,不需要重载通讯录
    itchat.send_msg('Nice to meet you!',msg['RecommendInfo']['UserName'])

@itchat.msg_register(TEXT,isGroupChat=True)
def text_reply(msg):
    if msg['isAt']:
        itchat.send(u'@%s\u2005I received: %s '%(msg['ActualNickName'],msg['Content']),msg['FromUserName'])


itchat.auto_login(hotReload=True)

#向文件助手发送消息
itchat.send('Hello filehelper',toUserName='filehelper')

itchat.run()
0
1

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:67937次
    • 积分:1956
    • 等级:
    • 排名:千里之外
    • 原创:128篇
    • 转载:16篇
    • 译文:0篇
    • 评论:27条
    每个人都是过客,每个人都有故事
    也许深夜往往是人们内心最为脆弱的时刻。孤独,绝望,失意,无奈......这些复杂沉重的情绪会随着黑夜的来临不再躲藏。
    最新评论