作者: gamezz 時間: 2023-12-20 12:42 標題: 有無師兄有用官方whatsapp business api?
有無師兄有用官方whatsapp business api?
係唔係一定要經以下代理申請,
公司做物流的,想在每日送貨前發一個whatsapp msg通知今日送貨就係咁簡單
(唔好問點解唔用sms)
https://www.facebook.com/busines ... p&languages=yue
作者: freefdhk 時間: 2023-12-21 01:59
唔洗經代理都得. 要係fb到驗證返公司個br 果類野 .
好多資料去填. 仲要用埋信用卡. 唔俾用預付卡.
不過用左咁耐1蚊都未扣過. 要超過佢個數量先會要俾錢.
不過如果自己唔想驗證咁多野. 可能俾錢呢類代理買api 就實際得多.
作者: gamezz 時間: 2023-12-21 17:09
咁我試下慢慢研究,d中間收費萬萬聲
thanks
作者: gn01119056 時間: 2023-12-21 17:35
twilio果個係點樣?
作者: gamezz 時間: 2023-12-22 16:45
回覆 4# gn01119056
應該係 USD $0.005 for WhatsApp Session messages.
作者: 杜龍 時間: 2023-12-24 08:33
本帖最後由 杜龍 於 2023-12-24 18:09 編輯
疫情果時我整左個program fetch 強檢大廈提示send message, 研究過whatsapp但要收錢, 最後用, telegram bot 做.
- from tabula import read_pdf, convert_into
- from tabulate import tabulate
- from PyPDF2 import PdfFileReader
- from commonfunction import *
- from telethon.sync import TelegramClient
- from telethon.tl.types import InputPeerUser, InputPeerChannel
- from telethon import TelegramClient, sync, events
- from os.path import exists
- # get your api_id, api_hash, token
- # from telegram as described above
- api_id = 'xx'
- api_hash = 'xxx'
- message = "Working..."
- #BuildingPdfURL = 'https://www.chp.gov.hk/files/pdf/ctn.pdf'
- class ClsCTNPDF:
- def getDownloadPDFLocation(self):
- return self.pdfldownloadpath
- def __init__(self):
- self.pdfldownloadpath = f'/config/workspaces/WorkspacePython/PDFScrape/pdf/restriction-testing{gettime()}.pdf'
- self._building_pdf_url = Config().BuildingPdfURL
- self.scheduleuser = AppDBRepo().getAllChatIDandSchedule()
- logger.info('ini')
- def downloadpdf(self):
- if not exists(self.pdfldownloadpath):
- command = ["wget", "-O",
- "{}".format(self.pdfldownloadpath), "{}".format(self._building_pdf_url)]
- p = subprocess.Popen(command, stdout=subprocess.PIPE)
- out, err = p.communicate()
- logger.info("download out:{0}".format(out))
- if err:
- logger.error(err)
- return False
- return True
- def ConvertPDFtoJson(self):
- # reads table from pdf file
- # tables = read_pdf("abc.pdf",pages="all") #address of pdf file
- jsonpath = f'/config/workspaces/WorkspacePython/PDFScrape/pdf/ctn{gettime()}.json'
- convert_into(self.pdfldownloadpath, jsonpath,
- output_format="json", pages='all')
- jsonfile = open(jsonpath)
- self.data = json.load(jsonfile)
- jsonfile.close()
- return self.data
- def ExtractBuildingList(self, maindistrict, subdistrict):
- # if self.data is None:
- maindistrict = maindistrict.replace("區", "")
- subdistrict = subdistrict.replace("區", "")
- logger.info("filter district main district:{0}, sub district:{1}".format(
- maindistrict, subdistrict))
- self.downloadpdf()
- self.ConvertPDFtoJson()
- building_list = []
- for _d in self.data:
- for _i in _d['data']:
- addr = _i[1]['text']
- if len(addr) > 0 and (maindistrict in addr or (subdistrict in addr)):
- building_list.append(addr.replace('\r', ' '))
- self.building_list = building_list
- return self.building_list
- def getScheduleUserByChatID(self, chatid):
- return self.getTblScheduleByChatID(chatid)[0].tblUser
- def getTblScheduleByChatID(self, chatid):
- return list(filter(lambda s: s.tblUser.chat_id == chatid, self.scheduleuser))
- def sendTelegram(self, chatid):
- objuser = self.getScheduleUserByChatID(chatid)
- logger.info(
- f"Handling telegram msg for USER:{objuser.user_name}/chat id:({objuser.chat_id})")
- building_list = self.ExtractBuildingList(
- objuser.main_district, objuser.sub_district)
- if len(building_list) == 0:
- logger.info("===No building in main district:{0} or subdistrict: {1}, will not post message====".format(
- objuser.main_district, objuser.user_name))
- else:
- _greeting = f"{objuser.user_name.upper()} 您好!\r\n根據香港衞生防護中心最新的公告({getLocalTime().strftime('%Y-%B-%d %H:%M:%S')})\r\n{self._building_pdf_url}\r\n\r\n在您登記的地區 :\r\n{objuser.main_district}/{objuser.sub_district}\r\n\r\n以下是需要進行新冠病毒強檢的大廈名單 :\r\n"
- _strBuildings = _greeting + ("\r\n".join(building_list))
- logger.info(_strBuildings)
- dopost = True
- if dopost:
- SEND_URL = f'https://api.telegram.org/bot{Config().myToken}/sendMessage'
- requests.post(SEND_URL, json={
- 'chat_id': chatid, 'text': _strBuildings})
- def checkScheduleAndSendMsg(self):
- logger.info('======Schedule job started at %s=========',
- getLocalTime())
- chatids = set([int(s.tblUser.chat_id)
- for s in self.scheduleuser])
- logger.info('chatids:{0}'.format(chatids))
- for chatid in chatids:
- sch = self.getTblScheduleByChatID(chatid)
- objuser = sch[0].tblUser
- LstSchedule = set(int(s.tblSchedule.schedule.strftime("%H"))
- for s in sch)
- currenthour = getCurrentHour()
- logger.info('Schedules for user {0}({1}):{2}, current hour:{3}'.format(
- objuser.user_name, chatid, LstSchedule, currenthour))
- #logger.info("current hour: {0}".format(currenthour))
- if (currenthour in LstSchedule):
- # if (currenthour in LstSchedule) or True:
- logger.info(
- '===========Current hour matches schedule============')
- self.sendTelegram(chatid)
- else:
- logger.info("======Current hour not in user:{0}'s schedule=====".format(
- objuser.user_name))
- try:
- ClsCTNPDF().checkScheduleAndSendMsg()
- except Exception as e:
- logging.error('Error', exc_info=e)
- # your phone number
- phone = '+85212347897'
作者: freefdhk 時間: 2023-12-25 21:37
開個帳號
https://developers.facebook.com/apps/?show_reminder=true
建立應用程式 (可能要公司BR上傳)
Whatsapp -> API 設定 -> 建立號碼.
然後入信用卡.
應該就可以玩用佢來收發 Whatsapp Message . (要自己搞埋個永久 api key 先唔會過期, google 找教學吧. )
- curl -i -X POST `
- https://graph.facebook.com/v17.0/xxxxxxxxxxxxxxxxxxxxx/messages `
- -H 'Authorization: Bearer xxxxxxxxxxxxxxxxxxxxx' `
- -H 'Content-Type: application/json' `
- -d '{ "messaging_product": "whatsapp", "to": "852xxxxxxxxxxxxxxxxxxxxx", "type": "template", "template": { "name": "hello_world", "language": { "code": "en_US" } } }'
不過如果要玩埋收whatsapp message 就要配合好多野.
作者: gamezz 時間: 2023-12-27 16:53
回覆 7# freefdhk
想問下,api endpoint 個 Phone-Number-ID 係唔係唔可以用佢試果個?
[attach]2404333[/attach]
作者: freefdhk 時間: 2023-12-28 02:53
測試號是可以傳香港號碼. 不過 要驗證綁定 收信息的號碼. 佢唔會比你拎來發廣告.
你在 Whatsapp -> 快速入門 > API 設定
他的專用測試頁面到試會比較簡單.
作者: gamezz 時間: 2023-12-29 09:58
回覆 9# freefdhk
Thanks. 這個真係清楚易明好多
作者: Jimmy0911 時間: 2024-1-2 01:40
回覆 1# gamezz
如果Business Account就要經Business API
如果個人Account就好似#2 咁講,用公司BR之類拎佢API黎用

