Skip to content

Commit

Permalink
bitrix:added add_deal
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Rozhkov committed Apr 23, 2019
1 parent 09c7e79 commit 8c88c89
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions db_api_bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def get_all_data(i, s, **d):
'Share your sheet with [email protected].'
'Then just send me your spreadsheet name and let\'s get started!'),
'react' : tgflow.action(open_sheet, react_to='text'),
'prepare' : [analytics.send_pageview, bitrix.add_lead],
'prepare' : [analytics.send_pageview, bitrix.add_lead, bitrix.add_contact],
},

States.CHOOSE:{
Expand All @@ -67,7 +67,7 @@ def get_all_data(i, s, **d):
{'Insert row' : tgflow.action(States.PUT)},
{'Recieve all data' : tgflow.action(get_all_data)}
],
'prepare' : [analytics.send_pageview, bitrix.add_contact]
'prepare' : [analytics.send_pageview, bitrix.add_deal]
},

States.PUT:{
Expand Down
19 changes: 16 additions & 3 deletions db_api_bot/database_api/bitrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ def add_lead(self, i, s, **d):
}
}
lead_id = self._client.call_method('crm.lead.add', payload)['result']
return {'lead_id': lead_id}
return {'bitrix24.lead_id': lead_id}

def add_contact(self, i, s, **d):
self._check_tokens()
lead = self._client.call_method('crm.lead.get', {'id': d['lead_id']})['result']
lead = self._client.call_method('crm.lead.get', {'id': d['bitrix24.lead_id']})['result']
payload = {
'fields': {
"NAME": lead['NAME'],
Expand All @@ -47,4 +47,17 @@ def add_contact(self, i, s, **d):
}
}
contact_id = self._client.call_method('crm.contact.add', payload)['result']
return {'contact_id': contact_id}
return {'bitrix24.contact_id': contact_id}

def add_deal(self, i, s, **d):
self._check_tokens()
payload = {
'fields' : {
"TITLE": "Deal with user {}".format(i.from_user.id),
"STAGE_ID": "NEW",
"COMPANY_ID": 3,
"CONTACT_ID": d['bitrix24.contact_id'],
}
}
deal_id = self._client.call_method('crm.deal.add', payload)['result']
return {'bitrix24.deal_id': deal_id}

0 comments on commit 8c88c89

Please sign in to comment.