当获得一个新会员,会希望使用者能够了解如何使用系统,会提供使用者一份指引如何使用,同时也希望使用者尽快进行第一笔消费,获得正向回馈,也就是所谓新会员注册礼;同时在使用者封锁官方帐号嫌太烦了一阵子後,如果使用者重新追踪or解除封锁,这时也建议推送一个专属优惠(回归礼包),今天来实作这个功能吧
这个Event会在使用者加官方帐号为好友与解除封锁时触发,其大致的结构如下:
{
"event":[
{
"replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
"type": "follow",
"mode": "active",
"timestamp": 1462629479859,
"source": {
"type": "user",
"userId": "U4af4980629..."
}
}
]
}
需要的参数为source与replyToken,运用昨天撰写的function INS_UPD_cus(self, prof),当是新用户时回传1,是老客户时回传2,於是可以依据此给出欢迎讯息
当使用者加入时,如果是新使用者,则显示"欢迎铁人赛的勇者",如果以前曾经加为好友,则显示欢迎铁人赛的勇者回来
@handler.add(FollowEvent)
def handle_follow(event):
prof = line_bot_api.get_profile(event.source.user_id)
r = dbpm.INS_UPD_cus(prof)
if r == 1:msg = "Hello 欢迎铁人赛的勇者"
else: msg = "Hello 欢迎铁人赛的勇者回来"
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text=msg))
一样从拉一个表格开始
CREATE TABLE IF NOT EXISTS public.coupon
(
cpid bigint NOT NULL DEFAULT nextval('coupon_cpid_seq'::regclass),
type text COLLATE pg_catalog."default" NOT NULL,
code text COLLATE pg_catalog."default" NOT NULL,
"Activate" boolean NOT NULL DEFAULT false,
s_time timestamp with time zone,
e_time timestamp with time zone,
times integer,
userids text[] COLLATE pg_catalog."default",
CONSTRAINT coupon_pkey PRIMARY KEY (cpid)
)
TABLESPACE pg_default;
你有3种预先定义的自动增加变数方式可以选择
Type | Size | Range |
---|---|---|
SMALLSERIAL | 2byte | 1-32,767 |
SERIAL | 4byte | 1-2,147,483,647 |
BIGSERIAL | 8byte | 1-922,337,2036,854,775,807 |
def INS_CPN(self, id, cptype):
if(cptype == "new"):
import string, random
code = ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(8))
s_time = datetime.now().isoformat()
e_time = (datetime.now() + timedelta(days=7)).isoformat()
cur = self.conn.cursor()
id = '{' + id + '}'
query = sql.SQL("INSERT INTO {}(type, code, s_time, e_time, times, userids) VALUES (%s, %s, %s, %s, %s, %s);").format(sql.Identifier('coupon'))
cur.execute(query, ("NBcp", code, s_time, e_time, str(1), id))
self.conn.commit()
cur.close()
return 1, code
else:
print()
return 0, "placeholder Due no coupon"
今天还在弄Line的官方帐号介面模板,暂时还没弄明白,先写点别的
昨天的文章已把场景与平面侦测做好,今天要继续说明角色蛇的移动 目录 移动机制说明 变数宣告 介面按钮...
在前面的一些示例中,我们见过 $,@ 等等,这样的符号,但没有详细地说明这些符号的用途,今天我们就来...
把2个table的资料union起来,但2个table很相似,却有些栏位差异. 怎麽快速的找出共同栏...
这篇的上一篇:https://ithelp.ithome.com.tw/articles/10283...
心理学专家主理企业培训 运用科学解决不同企业与组织问题,包括团队协作、客户关系,助你达成业绩目标。 ...